How to check if a folder exists

后端 未结 10 1870
滥情空心
滥情空心 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 21:45

    Generate a file from the string of your folder directory

    String path="Folder directory";    
    File file = new File(path);
    

    and use method exist.
    If you want to generate the folder you sould use mkdir()

    if (!file.exists()) {
                System.out.print("No Folder");
                file.mkdir();
                System.out.print("Folder created");
            }
    

提交回复
热议问题