如何在Java中创建一个目录? [英] How to create a directory in Java?
本文介绍了如何在Java中创建一个目录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何创建目录/文件夹?
How do I create Directory/folder?
一旦我测试了 System.getProperty(user.home);
只有当新文件夹不存在时,我必须创建一个目录(目录名新文件夹)。
I have to create a directory (directory name "new folder" ) if and only if new folder does not exist.
推荐答案
File theDir = new File("new folder");
// if the directory does not exist, create it
if (!theDir.exists()) {
System.out.println("creating directory: " + theDir.getName());
boolean result = false;
try{
theDir.mkdir();
result = true;
}
catch(SecurityException se){
//handle it
}
if(result) {
System.out.println("DIR created");
}
}
这篇关于如何在Java中创建一个目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文