Test if a file exists

    1

    45

    fileexists
    Java Public Recipes

    Test if a file exists on the filesystem

    Check if the path exists on the filesystem

    import java.io.File;
    
    File f = new File(filePathString);
    if(f.exists()) { 
      // the file exists
    }
    
    Codiga Logo
    Codiga Hub
    • Rulesets
    • Playground
    • Snippets
    • Cookbooks
    Legal
    • Security
    • Privacy Policy
    • Code Privacy
    • Terms of Service
    soc-2 icon

    We are SOC-2 Compliance Certified

    G2 high performer medal

    Codiga – All rights reserved 2022.