开发者

Android - FileNotFoundException when opening file with blank characters in the name

开发者 https://www.devze.com 2023-01-24 23:41 出处:网络
I am building an android application and have the follo开发者_C百科wing problem. When I want to open a file from the sdcard using FileInputStream and if the file name contains a blank character, I get

I am building an android application and have the follo开发者_C百科wing problem. When I want to open a file from the sdcard using FileInputStream and if the file name contains a blank character, I get the FileNotFoundException. If there are no blank characters, everything works fine. So, if I am to open for example: "My file.ext" it raises an exception, and if the file name is "Myfile.ext" everything is fine.

Any clues on how to resolve that will be much appreciated.

Regards


You will need to use an escape character to specific that there is a blank in the file name. I believe it is a '\'...

So it would be like this "my\ textfile.txt"


You could try to let android parse a certain file and open it

 File file = new File(Uri.parse(path+"file name.txt"));
 FileInputStream inputStream = new FileInputStream(file);

Uri should parse your filenames correctly.

0

精彩评论

暂无评论...
验证码 换一张
取 消