- String strPath = "E:\\a\\aa\\aaa.txt";
- File file = new File(strPath);
- if(!file.exists())){
- file.createNewFile();
- }
这段代码,如果 E:\a\aa\ 文件夹不存在,会报错。
- String strPath = "E:\\a\\aa\\aaa.txt";
- File file = new File(strPath);
- if(!file.exists())){
- file.file.mkdirs();
- }
- String strPath = "E:\\a\\aa\\aaa.txt";
- File file = new File(strPath);
- File fileParent = file.getParentFile();
- if(!fileParent.exists()){
- fileParent.mkdirs();
- }
- file.createNewFile();