androidfilefile-io

Android; Check if file exists without creating a new one


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?


Solution

  • 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.