0

I am trying to use CSVWriter to write to a file for my android project.

As part of my folder structure I have created a folder called myData and within that have a CSV file called results.csv

String csvpath = Environment.getExternalStorageDirectory().getAbsolutePath();
CSVWriter csvw = new CSVWriter(new FileWriter(csvpath+"/myData/results.csv"));

However I get the following exception

java.io.FileNotFoundException: /storage/emulated/0/myData/results.csv: open failed: ENOENT (No such file or directory)

I have also added:

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

How can I get the correct path for this file?

2
  • Did you require the permission to write? Commented Nov 29, 2014 at 16:24
  • The READ permission is optional - WRITE includes it already. Commented Nov 29, 2014 at 16:46

1 Answer 1

1

The issue is you have to create the myData Folder Otherwise it will throws the exception.

    File dir=new File( Environment.getExternalStorageDirectory(), "MyDate");
    if(!dir.exists()){
        dir.mkdir();
    }
    CSVWriter csvw = new CSVWriter(new FileWriter(dir.getAbsolutePath()+"/results.csv"));

In Manifest:

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
Sign up to request clarification or add additional context in comments.

1 Comment

Just tried it, it is now working. Thank you for this!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.