1、判斷文件是否存在,不存在創(chuàng)建文件 - File file=new File("C:\\Users\\QPING\\Desktop\\JavaScript\\2.htm");
- if(!file.exists())
- {
- try {
- file.createNewFile();
- } catch (IOException e) {
-
- e.printStackTrace();
- }
- }
2、判斷文件夾是否存在,不存在創(chuàng)建文件夾 - File file =new File("C:\\Users\\QPING\\Desktop\\JavaScript");
-
- if (!file .exists() && !file .isDirectory())
- {
- System.out.println("http://不存在");
- file .mkdir();
- } else
- {
- System.out.println("http://目錄存在");
- }
|