以下是實現的代碼
package com
import java
import java
import java
public class ReadFile {
public ReadFile() {}
/**
* 刪除某個文件夾下的所有文件夾和文件
* @param delpath String
* @throws FileNotFoundException
* @throws IOException
* @return boolean
*/
public static boolean deletefile(String delpath) throws FileNotFoundException
IOException {
try {
File file = new File(delpath);
if (!file
System
file
}
else if (file
System
String[] filelist = file
for (int i =
File delfile = new File(delpath +
if (!delfile
System
System
System
delfile
System
}
else if (delfile
deletefile(delpath +
}
}
file
}
}
catch (FileNotFoundException e) {
System
}
return true;
}
/**
* 刪除某個文件夾下的所有文件夾和文件
* @param delpath String
* @throws FileNotFoundException
* @throws IOException
* @return boolean
*/
public static boolean readfile(String filepath) throws FileNotFoundException
IOException {
try {
File file = new File(filepath);
if (!file
System
System
System
System
}
else if (file
System
String[] filelist = file
for (int i =
File readfile = new File(filepath +
if (!readfile
System
System
System
}
else if (readfile
readfile(filepath +
}
}
}
}
catch (FileNotFoundException e) {
System
}
return true;
}
public static void main(String[] args) {
try {
readfile(
//deletefile(
}
catch (FileNotFoundException ex) {
}
catch (IOException ex) {
}
System
}
}
From:http://tw.wingwit.com/Article/program/Java/hx/201311/26965.html