Java的createNewFile() - 它还会创建目录? [英] Java's createNewFile() - will it also create directories?
本文介绍了Java的createNewFile() - 它还会创建目录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个条件来检查某个文件是否存在,然后继续( ./ logs / error.log
)。如果没有找到我想要创建它。但是,将
I've got a conditional to check if a certain file exists before proceeding (./logs/error.log
). If it isn't found I want to create it. However, will
File tmp = new File("logs/error.log");
tmp.createNewFile();
还创建 logs /
存在?
推荐答案
否。
使用 tmp.getParentFile()。 mkdirs()
创建文件之前。
这篇关于Java的createNewFile() - 它还会创建目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文