2

I have a bizarre problem. I write a file to the SD card and then I remove the SD card. With the card removed, I then check for the existence of the file with File.exists.

The path to the file clearly indicates /mnt/sdcard/MyAppFolder/.....

So with:

File f = new File(filename);

Boolean exists = f.exists();

it returns true. How is this possible. The SD card is not even inserted. I stopped and re-ran the app but it always returns true. Wow Android is super!! It even keeps a connection to your SD card no matter where it is. Seriously folks, what am I doing wrong?

Polaris431
  • 481
  • 1
  • 5
  • 14
  • Did you unmount the SD card before physically removing it? – Austin Hanson Aug 05 '11 at 17:09
  • Oh. Wait a second. I'm debugging in Eclipse and when I removed the physical SD card, I completely forgot that the Android SDK probably is creating a virtual SD card. Sorry for asking. – Polaris431 Aug 05 '11 at 17:12
  • Possible duplicate of [Why does 'File.exists' return true, even though 'Files.exists' in the NIO 'Files' class returns false](https://stackoverflow.com/questions/30520179/why-does-file-exists-return-true-even-though-files-exists-in-the-nio-files) – GianhTran Jun 25 '18 at 09:31
  • Just had this problem, and it turns out the file.exists() was always true when inside a try..catch block ?! Taking it out of that block fixed it for me – Mike Redrobe Aug 23 '19 at 14:55

0 Answers0