1
File external = getExternalFilesDir(null);

//fd is stringbuffer whose value is "year1:semester:2"

File file = new File(external,""+fd.toString()+".txt"); // <----error

FileOutputStream fos = new FileOutputStream(file);
fos.write(store.getBytes());
fos.close();

This is the exception generated:

W/System.err(29169): java.io.FileNotFoundException: /storage/sdcard0/Android/data/com.example.ddu/files/Year:1Semester:2.txt: open failed: EINVAL (Invalid argument)
1
  • @Pieter please be more careful when editing, as you introduced additional whitespace not in the original within the path name displayed in the error. Commented May 30, 2014 at 18:28

1 Answer 1

5

You cannot create a file which has a colon (:) in its name. Replace the colon with something else.

Sign up to request clarification or add additional context in comments.

3 Comments

this code is working in my device...its just not working in some devices
yes..thank you :) ...it worked...but this is really confusing why was the above code running successfully in some devices and giving exceptions in others?
See the problem is with the device. Certain devices/OS reject some characters as valid file names. For example in Windows you cannot have a file with : or / or > or < in the name. This is platform specific. Some platform may not consider these invalid. I hope you understood. Please accept as the answer. :)

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.