在根据包含路径的File时,如果目录不存在,则会报:java.io.FileNotFoundException: d:\test\124665\2\124665_2_1.dwg (系统找不到指定的路径。)
解决方案:
File file = new File("d:/test/" + path);
if(file.getParentFile() != null && !file.getParentFile().exists()) {
file.getParentFile().mkdirs();
}
本文介绍了解决因目录不存在而导致的FileNotFoundException的方法。通过检查文件的父目录是否存在,并在不存在的情况下创建所需的目录层级。
365

被折叠的 条评论
为什么被折叠?



