Christian
Christian

Reputation: 26387

Android writing to a CSV file via OpenCsv

I try to write to a Csv file via:

mFileWriter = new FileWriter(
        "/sdcard/program/file");

mCsvWriter = new CSVWriter(mFileWriter);

At the moment it throws an exception that the file doesn't exist. It's true that the file doesn't exist. What's the easiest way to create the file?

Upvotes: 0

Views: 2416

Answers (1)

EboMike
EboMike

Reputation: 77732

Does the FILE not exist, or the DIRECTORY it's supposed to go into?

If you want to create a directory structure, you can always do

File file = new File("/full/path/to/file");
file.mkdirs();

This will create any path leading up to this file that doesn't exist yet.

I suppose the missing quotes around your file name are a typo?

Upvotes: 2

Related Questions