文件夹下目录文件的迭代现实示例2

package math;
import java.io.*;

public class Test {
public static String List(File f) {
String optionStr = null;
String tempStr = null;
String cc2 = f.getPath().toString();
//System.out.println(cc2);
optionStr = "

1<option>" + cc2 + "</option>

";
String[] name = f.list();
for (int i = 0; i < name.length; i++) {
File n = new File(f, name[i]);
if (n.isDirectory())
tempStr = List(n);
if (tempStr == null) {
tempStr = " ";
}

String cc1 = f.getParent().toString();
String cc = f.getPath().toString();
if (cc != cc2) {
//System.out.println(f.getPath());
}
optionStr = optionStr + tempStr;
}
return optionStr;
}

public static void main(String[] s) {
System.out.println(
List(
new File("D:\\ea\\wlserver6.0\\config\\WLSD11\\applications\\LabsWebApp")));
}
}

Published At
Categories with Web编程
comments powered by Disqus