主要开发中遇到一点小的坑,在代码编写过程中一点随意造成了不必要的问题,没什么技术含量,就是对api熟识度
不够,仅供参考把玩!!
String parentPath = "e:\\java";
String childPath = "test\\io.txt";
File file = new File(parentPath, childPath);
if (!file.exists()){ //right
File parentFile = file.getParentFile();
if (!parentFile.mkdirs() || !parentFile.isDirectory()){
throw new IOException("not a Directory");
}
file.createNewFile();
}
if (!file.exists()){ //error
if (!file.mkdirs()){
throw new IOException("create Directory error");
}
file.createNewFile();
}