Skip to content Skip to sidebar Skip to footer

IllegalArgumentException: File Contains A Path Separator Android

I'm trying to write to an output file on my HTC One and get the following message in the LogCat: 11-21 08:05:18.228: W/System.err(6609): java.lang.IllegalArgumentException: File /

Solution 1:

The openFileInput method will not accept path separators.('/')

it accepts only the name of the file which you want to open/access. so change the statement

outputStream = openFileOutput(patternDirectory.getAbsolutePath().toString(), Context.MODE_APPEND);

to

outputStream = new FileOutputStream (new File(patternDirectory.getAbsolutePath().toString()), true); // true will be same as Context.MODE_APPEND

Solution 2:

One problem may be the fact that you do: Environment.getExternalStorageDirectory().getAbsolutePath().toString()+"/com.example.pattern1/myfile.txt" You create a directory that has name myfile.txt


Post a Comment for "IllegalArgumentException: File Contains A Path Separator Android"