1、判断文件是否存在,不存在创建文件
- File file=new File("C:\\Users\\QPING\\Desktop\\JavaScript\\2.htm");
- if(!file.exists())
- {
- try {
- file.createNewFile();
- } catch (IOException e) {
-
- e.printStackTrace();
- }
- }
2、判断文件夹是否存在,不存在创建文件夹
- File file =new File("C:\\Users\\QPING\\Desktop\\JavaScript");
- if (!file .exists() && !file .isDirectory())
- {
- System.out.println("//不存在");
- file .mkdir();
- } else
- {
- System.out.println("//目录存在");
- }
java判断文件是否存在
原文:http://www.cnblogs.com/yiguangchao9999/p/5462753.html