-2

I am trying to save a file for quite some time, but I am either getting the error ENOENT (no such file or directory) or EACCES (no permission).
This code gives me the ENOENT:

String fileName = "/testCSV1.csv";
File path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOCUMENTS);

File f = new File(path, fileName);
CSVWriter writer;  

I get the EACCES when I try it via this:

String fileName = "/testCSV1.csv";
String baseDir = Environment.getExternalStorageDirectory().getAbsolutePath();
String filePath = baseDir + File.separator + fileName;
File f = new File(filePath);
CSVWriter writer;  

Even thought I have both permissions:

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>

So what do I have to do to get this working and get this file saved?

1 Answers1

2

I'm sure you have not asked the permission at run time. So enable these permission explicitly from setting and try again. From Marsh mellow you have to grant permissions at runtime even after declaring them in manifest. Hope this helps.

Kaushal28
  • 5,377
  • 5
  • 41
  • 72