简体   繁体   中英

File operations doesn't work sometimes

Something very strange is happenning in my app. I am creating 2 folders in the SD card if they not exist, and downloading some images from a URL if they not exist in the SD card. Sometimes, when I run the application, the program checks if the folders exists and also the images, as they are exists, it continues and there's nothing wrong. But often when I run the application, it alerts me that the folders not exists and that it didn't even managed to create those folders, and afterwards I'm getting a "File not found exception" when it tries to download the images who already exists in my SD card.

PS: I tried it with 2 devices and the same happens, sometimes works, sometimes doesn't.

What could be the problem here?

Actually before accessing files from external storage you have to check whether External storage is present (Available) or not on device (It possible if device's sdcard is mounted on System). For this You have to check the sate of External Storage as Mounted or Not.

Look at this Link for more info..

http://developer.android.com/guide/topics/data/data-storage.html#filesExternal

Now solution:

If you find external storage is not available then you can store your files at Internal Storage on temporary basis (Then you can move these files to External Storage when it present).

So My link also help you in how to access Internal Storage in Android.

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