Je reçois une exception FileNotFoundException sur la ligne où je déclare le FileOutputStream. Je ne suis pas vraiment sûr pourquoi cela se produit particulièrement depuis que je crée un nouveau fichier avant de créer le FileOutputStream. Je n'ai pas affiché toute la fonction, mais en gros, il désinscrit les capteurs du gyroscope et de l'accéléromètre et écrit leur sortie dans un fichier .csv. Toute aide serait grandement appréciée car je n'ai aucune idée de ce qui ne va pas.Android: Java.io.fileNotFoundException
protected void stopRecording() throws IOException{
sm.unregisterListener(this);
File path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
//file name is the current date and time
cal = Calendar.getInstance(TimeZone.getDefault());
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd_hh:mm:ss");
String output = sdf.format(cal.getTime()).toString();
File file = new File(path, output+ "_A" + ".csv");
FileOutputStream fos = new FileOutputStream(file);
out = new BufferedWriter(new OutputStreamWriter(fos));
for(int i = 0; i < a.size(); i++){
try {
out.write(a.get(i));
} catch (IOException e1) {
e1.printStackTrace();
}
}
03-22 11: 43: 40,845 18684-18684 /? W/System.err: java.io.FileNotFoundException: /storage/emulated/0/Pictures/2016-03-22_11:43:40_A.csv: ouverture échouée: EACCES (Autorisation refusée) 03-22 11: 43: 40.859 18684-18684 /? W/System.err: à libcore.io.IoBridge.open (IoBridge.java:452) 03-22 11: 43: 40.859 18684-18684 /? W/System.err: à java.io.FileOutputStream. (FileOutputStream.java:87) 03-22 11: 43: 40.859 18684-18684 /? W/System.err: à java.io.FileOutputStream. (FileOutputStream.java:72) 03-22 11: 43: 40.859 18684-18684 /? W/System.err: at com.example.alex.parkinsonsdiseaseapp.TestEnvironmentActivity.stopRecording (TestEnvironmentActivity.java:172) 03-22 11: 43: 40.859 18684-18684 /? W/System.err: à com.example.alex.parkinsonsdiseaseapp.TestEnvironmentActivity $ 3.onClick (TestEnvironmentActivity.java:120) 03-22 11: 43: 40.859 18684-18684 /? W/System.err: at android.view.View.performClick (View.java:5226) 03-22 11: 43: 40.859 18684-18684 /? W/System.err: at android.view.View $ PerformClick.run (View.java:21266) 03-22 11: 43: 40.859 18684-18684 /? W/System.err: at android.os.Handler.handleCallback (Handler.java:739) 03-22 11: 43: 40.859 18684-18684 /? W/System.err: at android.os.Handler.dispatchMessage (Handler.java:95) 03-22 11: 43: 40.859 18684-18684 /? W/System.err: at android.os.Looper.loop (Looper.java:168) 03-22 11: 43: 40.859 18684-18684 /? W/System.err: at android.app.ActivityThread.main (ActivityThread.java:5845) 03-22 11: 43: 40.859 18684-18684 /? W/System.err: à java.lang.reflect.Method.invoke (méthode native) 03-22 11: 43: 40.859 18684-18684 /? W/System.err: at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run (ZygoteInit.java:797) 03-22 11: 43: 40.859 18684-18684 /? W/System.err: at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:687) 03-22 11: 43: 40.859 18684-18684 /? W/System.err: Causé par: android.system.ErrnoException: ouverture échouée: EACCES (autorisation refusée) 03-22 11: 43: 40.859 18684-18684 /? W/System.err: at libcore.io.Posix.open (méthode native) 03-22 11: 43: 40.859 18684-18684 /? W/System.err: à libcore.io.BlockGuardOs.open (BlockGuardOs.java:186) 03-22 11: 43: 40.860 18684-18684 /? W/System.err: à libcore.io.IoBridge.open (IoBridge.java:438) 03-22 11: 43: 40.860 18684-18684 /? W/System.err: ... 13 plus
Je pense que vous ne pouvez pas utiliser: dans les noms de fichiers. – DonLeopardo
Je l'ai essayé. Cela n'a pas fonctionné. –
Pouvez-vous ajouter 'file.createNewFile();' avant la déclaration fos? Ne devrait pas faire la différence mais vaut la peine d'essayer, je pense –