Android; Check if file exists without creating a new one

MBH picture MBH · Apr 26, 2013 · Viewed 219.9k times · Source

I want to check if file exists in my package folder, but I don't want to create a new one.

File file = new File(filePath);
if(file.exists()) 
     return true;

Does this code check without creating a new file?

Answer

Maikel Bollemeijer picture Maikel Bollemeijer · Apr 26, 2013

Your chunk of code does not create a new one, it only checks if its already there and nothing else.

File file = new File(filePath);
if(file.exists())      
//Do something
else
// Do something else.