java.lang.IllegalArgumentException: contains a pat

2019-01-02 18:41发布

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";

标签: android
7条回答
萌妹纸的霸气范
2楼-- · 2019-01-02 19:20

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.

查看更多
登录 后发表回答