我正在尝试用Java创建一个新的目录,但它不起作用。我想知道为什么,因为我先尝试了mkdir(),然后又尝试了mkdirs(),它被认为会创建不存在的目录。
我写道:
boolean status = new File("C:\\Users\\Hito\\Desktop\\test").mkdir();
// status = false然后我写道
boolean status = new File("C:\\Users\\Hito\\Desktop\\test").mkdirs();
// status still = false.一条线索?
发布于 2013-02-03 20:19:18
File file = new File("C:/Users/Hito/Desktop/test");
file.mkdirs();
file.createNewFile();发布于 2013-02-03 20:20:55
这样打字速度更快,而且不需要双斜杠:
boolean status = new File("C:/Users/Hito/Desktop/test").mkdir();如果仍然出现错误,请检查父目录是否存在,以及文件是否可写。
String path = "C:/Users/Hito/Desktop/";
File file = new File(path);
If (!path.exists()) {
System.out.println("path does not exist:" + path);
} else {
File dir = new File(path + "test");
if (!dir.canWrite()) {
System.out.println("dir not writeable" + path + "test");
}
}发布于 2013-02-03 20:19:11
检查您的权限
试试看:
boolean status = new File("C:\\Users\\Hito\\Desktop\\test").canWrite();https://stackoverflow.com/questions/14672375
复制相似问题