java.lang.IllegalArgumentException: contains a path separator
openFileInput()
doesn't accept paths, only a file name
if you want to access a path, use File file = new File(path)
and corresponding FileInputStream
The solution is:
FileInputStream fis = new FileInputStream (new File(NAME_OF_FILE)); // 2nd line
The openFileInput method doesn't accept path separators.
Don't forget to
fis.close();
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 subdirectory Dir
.
You cannot access sub-directories using the above method.
Try something like:
FileInputStream fIS = new FileInputStream (new File("/Dir/data.txt"));
This method opens a file in the private data area of the application. You cannot open any files in subdirectories in this area or from entirely other areas using this method. So use the constructor of the FileInputStream
directly to pass the path with a directory in it.