How to check if a folder exists

后端 未结 10 1875
滥情空心
滥情空心 2020-11-28 21:21

I am playing a bit with the new Java 7 IO features, actually I trying to receive all the xml files of a folder. But this throws an exception when the folder does not exist,

10条回答
  •  暖寄归人
    2020-11-28 22:09

    We can check files and thire Folders.

    import java.io.*;
    public class fileCheck
    {
        public static void main(String arg[])
        {
            File f = new File("C:/AMD");
            if (f.exists() && f.isDirectory()) {
            System.out.println("Exists");
            //if the file is present then it will show the msg  
            }
            else{
            System.out.println("NOT Exists");
            //if the file is Not present then it will show the msg      
            }
        }
    }
    

提交回复
热议问题