1. Determine whether the file exists and create a file that does not exist File file =new File("C:\\Users\\QPING\\Desktop\\JavaScript"); //create the folder if it doesn't exist if (!file .exists() && !file .isDirectory()) { System.out.println("// does not exist"); file .mkdir(); } else { System.out.println("//Directory exists"); }
2. Determine whether the folder exists, and create a folder if it does not exist
File file=new File("C:\\Users\\QPING\\Desktop\\JavaScript\\2.htm"); if(!file.exists()) { try { file.createNewFile(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace (); } }