Android

Calling openFileInput(String name) gives java.lang.IllegalArgumentException: contains a path separator

Calling openFileInput(String name)

To get InputStream from file you can use these methods by calling openFileInput(String name) or FileInputStream(File file). But there’s some difference between these methods purpose.

When using this method openFileInput(String name), to get FileInputStream

If we use name parameter as some external SDK File path, app will crash giving this error

 java.lang.IllegalArgumentException: contains a path separator

which means, this method doesn’t accepts full path of a file with separators. It can just access and, Open a private file associated with this Context’s application package for reading. So, you can just give a FileName.

But, to get FileInputStream with some external SDK path you can simply use,

FileInputStream fis = new FileInputStream (new File(file_path));

and don’t forget to close, at the end

fis.close();

Cheers 🙂

2 thoughts on “Calling openFileInput(String name) gives java.lang.IllegalArgumentException: contains a path separator

Leave a Reply

Your email address will not be published.