How to check if a directory exists in Java

1 Answer

0 votes
package javaapplication1;

import java.io.File;
import java.io.IOException;

public class JavaApplication1 {

    public static void main(String[] args) throws IOException {

        try {

            File file = new File("d://tmp");
            
            boolean dirExists = file.exists();

            if (dirExists) {
                System.out.println("directory exists");
            } else {
                System.out.println("directory not exists");
            }

        } catch (Exception e) {
            System.out.print(e);
        }
    }
}


/*
        
run:
  
directory exists
    
 */

 



answered Nov 17, 2016 by avibootz

Related questions

1 answer 171 views
1 answer 185 views
185 views asked Jul 12, 2020 by avibootz
1 answer 222 views
1 answer 196 views
1 answer 152 views
152 views asked Mar 10, 2017 by avibootz
2 answers 185 views
...