views:

63

answers:

1

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?

+2  A: 

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?

EboMike
Yes, the missing quotes are a typo.
Christian
This doesn't seem to work. file.mkdirs() returns false on my end.
Christian
From the documentation: "Returnstrue if the necessary directories have been created, false if the target directory already exists or one of the directories can not be created." 1. Did it already exist? 2. Do you have the permissions to create the structure? 3. Are you trying to create a directory with the same name as an existing file?
EboMike