- 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();