判斷文件是否存在,若是不存在則建立它

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();
	             }
	       }
	
	     }
}
相關文章
相關標籤/搜索