How to check if a folder exists

后端 未结 10 1882
滥情空心
滥情空心 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:50

    You need to transform your Path into a File and test for existence:

    for(Path entry: stream){
      if(entry.toFile().exists()){
        log.info("working on file " + entry.getFileName());
      }
    }
    

提交回复
热议问题