JAVA 创建也项目平级文件

 
 
String url = System.getProperty("user.dir") +"/logs/test.txt"
File file = new File(url);
if (!file.getParentFile().exists()) {//判断父目录路径是否存在,即test.txt前的I:\a\b\
try {
file.getParentFile().mkdirs();//不存在则创建父目录
file.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
}
 

 更多参考 :https://a52071453.iteye.com/blog/2185314

猜你喜欢

转载自www.cnblogs.com/louby/p/10838243.html