0

I have the following code:

    try{
             File sdCard = Environment.getExternalStorageDirectory();
             File directory = new File (sdCard.getAbsolutePath() + "/statReporter/");
             directory.mkdirs();

             //Path and name of XML file
             File file = new File(directory, appendTimeStamp("statReporter") + ".csv");
             FileOutputStream fOut = new FileOutputStream(file);
             OutputStreamWriter osw = new OutputStreamWriter(fOut);

             //Write to CSV File
             osw.write(message);
             osw.write(',');

             //Flush and close OutPutStreamWriter and close FileOutputStream
             osw.flush();
             osw.close();
             fOut.close();

             Log.d("File Logger:", "File write successfully!");

     }catch(IOException ioe){
             ioe.printStackTrace();
     }

I get the following exception:

java.io.FileNotFoundException: /mnt/sdcard/statReporter/Date:3/24/2013Time:11:932statReporter,.csv: open failed: ENOENT (No such file or directory)
Nermeen
  • 15,883
  • 5
  • 59
  • 72
wwjdm
  • 2,568
  • 7
  • 32
  • 61

2 Answers2

0

I found the error:

I changed the file name. Got rid of ":" and "/" and ","

wwjdm
  • 2,568
  • 7
  • 32
  • 61
0

in the file name Date:3/24/2013Time:11:932statReporter,.csv there is the / separator..which will be considered a directory.

Nermeen
  • 15,883
  • 5
  • 59
  • 72