public void visit(File dir) {
if (dir.isFile()) {
return;
}
File[] fs = dir.listFiles();
for (int i=0;i<fs.length;i++) {
if (fs[i].isFile()) {
parse(fs[i]);
}
else {
visit(fs[i]);
}
}
}
void parse(File f) {
//add your code here
}
if (dir.isFile()) {
return;
}
File[] fs = dir.listFiles();
for (int i=0;i<fs.length;i++) {
if (fs[i].isFile()) {
parse(fs[i]);
}
else {
visit(fs[i]);
}
}
}
void parse(File f) {
//add your code here
}
dir.list();
or
dir.listFiles(FileFilter ff);
import java.io.FileNotFoundException;/**
* @author Administrator
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/
public class ShowAllFile{
public void showFiles(String dir_path) throws FileNotFoundException {
File file = new File(dir_path);
if (!file.exists()) {
throw new FileNotFoundException();
}
if (file.isDirectory()) {
File[] fe = file.listFiles();
for (int i = 0; i < fe.length; i++) {
System.out.println(fe[i].toString());
showFiles(fe[i].toString());
}
}
}
public static void main(String[] args) throws FileNotFoundException {
ShowAllFile show = new ShowAllFile();
String dir_path="C:\\axis";
show.showFiles(dir_path);
}
}