Java程序中创建文件夹
public class MyTest {public static void main(String[] args) {MyTest mulutest = new MyTest();mulutest.newFolder("D:/abcds");mulutest.newFolders("D:/asdf/aaa/bbb");}public void newFolder(String folderPath) {String filePath = folderPath;filePath = filePath.toString();java.io.File myFilePath = new java.io.File(filePath);try {//文件夹是否已存在,不可使用exists()方法if (myFilePath.isDirectory()) {System.out.println("the directory is exists!");} else {//创建文件夹,mkdir只能创建一级文件夹myFilePath.mkdir();System.out.println("新建目录成功");}} catch (Exception e) {System.out.println("新建目录操作出错");e.printStackTrace();}}public void newFolders(String folderPath) {String filePath = folderPath;filePath = filePath.toString();java.io.File myFilePath = new java.io.File(filePath);try {//文件夹是否已存在,不可使用exists()方法if (myFilePath.isDirectory()) {System.out.println("the directory is exists!(文件夹已存在!)");} else {//创建文件夹,mkdirs可创建多级文件夹,如:D:/abcds/aaa/bbb,或D:/abcds等myFilePath.mkdirs();System.out.println(folderPath);System.out.println("新建目录成功");}} catch (Exception e) {System.out.println("新建目录操作出错");e.printStackTrace();}}}?