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


Cheers 🙂


  1. juvin | | Reply

    Totally copied from stack overflow.

    • Praveen | | Reply

      yes, copied… forgot to add the ref link at that time. just added ref link in post now.

Leave a Reply

Your email address will not be published. Required fields are marked *