简体   繁体   中英

Leading '/' while reading a file in Android

My file's actual location in SDcard is :

mnt/sdcard/Pictures/Images/IMG_20140127_123605.jpg

If I use the same for reading , for example :

FileInputStream fis = new FileInputStream("mnt/sdcard/Pictures/Images/IMG_20140127_123605.jpg");

The above case works fine :)

But, If I use them like :

String s="mnt/sdcard/Pictures/Images/IMG_20140127_123605.jpg";

FileInputStream fis = new FileInputStream(s);

The above case does not work, as it puts a leading '/'. and the file path becomes

/mnt/sdcard/Pictures/Images/IMG_20140127_123605.jpg

And therefore a java.io.FileNotFoundException is thrown

Please help me out in fixing this small issue.Thanks.

You have given a space after Image path. Change your code from

String s="mnt/sdcard/Pictures/Images/IMG_20140127_123605.jpg ";
FileInputStream fis = new FileInputStream(s);

to

String s="mnt/sdcard/Pictures/Images/IMG_20140127_123605.jpg";
FileInputStream fis = new FileInputStream(s);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM