I am working on android app and part of it is to import a PDF file from SDcard and then display it in text view. I am using itext to create a .txt file from the pdf. I am having a problem when displaying the content of the .txt file in text view. can anyone help please.
-
http://stackoverflow.com/questions/5963535/java-lang-illegalargumentexception-contains-a-path-separator ? – user3367946 Feb 06 '17 at 20:08
-
[http://stackoverflow.com/questions/5963535/java-lang-illegalargumentexception-contains-a-path-separator](http://stackoverflow.com/questions/5963535/java-lang-illegalargumentexception-contains-a-path-separator) – user3367946 Feb 06 '17 at 20:10
-
[http://stackoverflow.com/questions/5963535/java-lang-illegalargumentexception-contains-a-path-separator](http://stackoverflow.com/questions/5963535/java-lang-illegalargumentexception-contains-a-path-separator) – user3367946 Feb 06 '17 at 20:12
2 Answers
openFileInput()
will not accept path separators.('/'). It accepts only the name of the file which you want to open/access. So change the statement,
InputStream in = openFileInput(String.valueOf(filepath));
to,
FileInputStream in = FileInputStream(filepath);
Also there is no need to convert filepath
into String
as FileInputStream
can accept File
types.

- 2,493
- 1
- 14
- 27
Documentation for ContextWrapper.openFileInput()
specifically says you cannot provide a path.
name String: The name of the file to open; can not contain path separators.
openFileInput
is for dealing with private files, which I think means files your app creates for the purpose of your app, so it would be saved in your private app data directory.
I didn't read through your entire code snippet, but assuming you are instantiating the File
object correctly and you just want a FileInputStream
, you should be able to just instantiate one directly:
InputStream in = new FileInputStream(filepath);
Making sure your app has permission to access files.

- 476
- 3
- 3