I have a filename in my code as :
String NAME_OF_FILE="//sdcard//imageq.png";
FileInputStream fis =this.openFileInput(NAME_OF_FILE); // 2nd line
I get an error on 2nd line :
05-11 16:49:06.355: ERROR/AndroidRuntime(4570): Caused by: java.lang.IllegalArgumentException: File //sdcard//imageq.png contains a path separator
I tried this format also:
String NAME_OF_FILE="/sdcard/imageq.png";
I solved this type of error by making a directory in the onCreate event, then accessing the directory by creating a new file object in a method that needs to do something such as save or retrieve a file in that directory, hope this helps!
The solution is:
The openFileInput method doesn't accept path separators.
Don't forget to
at the end.
I got the above error message while trying to access a file from Internal Storage using
openFileInput("/Dir/data.txt")
method with subdirectoryDir
.You cannot access sub-directories using the above method.
Try something like:
openFileInput()
doesn't accept paths, only a file name if you want to access a path, useFile file = new File(path)
and correspondingFileInputStream
You cannot use path with directory separators directly, but you will have to make a file object for every directory.
NOTE: This code makes directories, yours may not need that...