I am getting a FileNotFoundException
on the line where I declare and initalize the FileOutputStream
. I'm not really sure why this is happening particularly since I make a new File
before I create the FileOutputStream
. I did not post the entire function, but basically it unregisters the gyroscope and accelerometer sensors and writes their output to a .csv file. Any help would be greatly appreciated because I have no idea what is wrong.
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: open failed: EACCES (Permission denied)
03-22 11:43:40.859 18684-18684/? W/System.err: at libcore.io.IoBridge.open(IoBridge.java:452)
03-22 11:43:40.859 18684-18684/? W/System.err: at java.io.FileOutputStream.<init>(FileOutputStream.java:87)
03-22 11:43:40.859 18684-18684/? W/System.err: at java.io.FileOutputStream.<init>(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: at 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: at java.lang.reflect.Method.invoke(Native Method)
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: Caused by: android.system.ErrnoException: open failed: EACCES (Permission denied)
03-22 11:43:40.859 18684-18684/? W/System.err: at libcore.io.Posix.open(Native Method)
03-22 11:43:40.859 18684-18684/? W/System.err: at libcore.io.BlockGuardOs.open(BlockGuardOs.java:186)
03-22 11:43:40.860 18684-18684/? W/System.err: at libcore.io.IoBridge.open(IoBridge.java:438)
03-22 11:43:40.860 18684-18684/? W/System.err: ... 13 more