判断文件是否存在,如果不存在则创建它

2019独角兽企业重金招聘Python工程师标准>>> hot3.png

public class kkk {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		 File file = new File("d:/test_filepp.txt");
         judeFileExists(file);
	}
	// 判断文件是否存在
	    public static void judeFileExists(File file) {
	        if (file.exists()) {
             System.out.println("file exists");
	        } else {
	            System.out.println("file not exists, create it ...");
	             try {
	                 file.createNewFile();
	             } catch (IOException e) {
	                // TODO Auto-generated catch block
	                 e.printStackTrace();
	             }
	       }
	
	     }
}

 

转载于:https://my.oschina.net/u/2531348/blog/743553

你可能感兴趣的:(判断文件是否存在,如果不存在则创建它)