File file = new File(...);
file.mkdirs(); //for several levels, without the "s" for one level
FileWriter fileWriter = new FileWriter(file);
fileWriter.write("...");
Creates the directory named by this abstract pathname, including any necessary but nonexistent parent directories. Note that if this operation fails it may have succeeded in creating some of the necessary parent directories.
Returns:
true if and only if the directory was created, along with all necessary parent directories; false otherwise
# 1 楼答案
它返回一个布尔值,以检查制作是否成功(如果磁盘已满或文件名为“upload”等,则会失败)
# 2 楼答案
见File.mkdirs()和File.mkdir()
# 3 楼答案
除了公认的答案之外,由于问题还提到了Apache Common IO库,我在下面报告了一个使用该库的解决方案:
这个解决方案使用来自包} 和方法^{} ,“生成一个目录,包括任何必要但不存在的父目录”
org.apache.commons.io
的类^{