近日在项目中遇到一个问题,需要在指定的目录下面,找到指定的文件。查找相关方法后,特将方法写出来以便日后用到。 public static File checkExist(String filepath)throwsException{File file=newFile(filepath);if(file.exists()) {//判断文件目录的存在System. out .println("文件夹存在!");if(file.isDirectory()){//判断文件的存在性System. out .println("文件存在!");}else{ file.createNewFile();//创建文件System. out .println("文件不存在,创建文件成功!");}}else{System. out .println("文件夹不存在!"); File file2=newFile(file.getParent()); file2.mkdirs();System. out .println("创建文件夹成功!");if(file.isDirectory()){System. out .println("文件存在!");}else{ file.createNewFile();//创建文件System. .println("文件不存在,创建文件成功!");}}returnfile;}