Created
July 30, 2014 01:29
-
-
Save dzwillpower/32a7510f1f72b9567fa0 to your computer and use it in GitHub Desktop.
创建文件夹 和递归删除文件夹
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.wits.dzwillpower; | |
import java.io.File; | |
public class DirectoryCreate { | |
public static void main(String[] args) { | |
deleteFile(new File("E:\\ProgrammeMaterial\\Android\\AndroidProgram\\3372\\1\\1")); | |
} | |
public static void deleteFile(File file) { | |
File[] temp = file.listFiles(); | |
for (int i = 0; i < temp.length; i++) { | |
System.out.println(temp[i].getName()); | |
if (temp[i].isDirectory()) { | |
if (temp[i].listFiles().length != 0) | |
deleteFile(temp[i]); | |
deleteDir(temp[i]); | |
} else { | |
temp[i].delete(); | |
} | |
} | |
} | |
private static void deleteDir(File file) { | |
if (file.listFiles().length == 0) | |
file.getAbsoluteFile().delete(); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.oppo.java; | |
import java.io.File; | |
public class RecursionCreateDir { | |
public static void main(String[] args) { | |
File rootFile; | |
File files = new File("E:\\A\\B\\C"); | |
rootFile = files; | |
if (!files.exists()) { | |
if (files.mkdirs()) { | |
System.out.println("创建多个目录成功"); | |
} else { | |
System.out.println("创建多个目录失败....."); | |
} | |
} | |
for (int i = 0; i < 100; i++) { | |
File file = new File(rootFile, String.valueOf(i)); | |
rootFile = file; | |
System.out.println("rootFile: " + rootFile); | |
if (!rootFile.exists()) { | |
if (rootFile.mkdir()) { | |
System.out.println("创建子目录成功"); | |
} else { | |
System.out.println("创建子目录失败"); | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment