JAVA列出某文件夹下的所有文件
2009-11-09 21:01:18 来源:WEB开发网核心提示:view plaincopy to clipboardPRint?import java.io.*; public class ListFiles { private static String s = ""; private static BufferedReader in = new Buffe
view plaincopy to clipboardPRint?
import java.io.*;
public class ListFiles {
private static String s = "";
private static BufferedReader in = new BufferedReader(
new InputStreamReader(System.in));
public static void main(String[] args) {
try {
s = in.readLine();
getFileList(s);
in.close();
} catch (IOException e) {
e.printStackTrace();
}
}
public static void getFileList(String directory) {
File f = new File(directory);
File[] files = f.listFiles();
for (int i = 0; i < files.length; i++) {
if (files[i].isFile()) {
System.out.println("文件:" + files[i]);
} else {
System.out.println("目录:" + files[i]);
// System.out.println("目录绝对地址:" + files[i].getAbsolutePath());
getFileList(files[i].getAbsolutePath());
}
}
}
}
import java.io.*;
public class ListFiles {
private static String s = "";
private static BufferedReader in = new BufferedReader(
new InputStreamReader(System.in));
public static void main(String[] args) {
try {
s = in.readLine();
getFileList(s);
in.close();
} catch (IOException e) {
e.printStackTrace();
}
}
public static void getFileList(String directory) {
File f = new File(directory);
File[] files = f.listFiles();
for (int i = 0; i < files.length; i++) {
if (files[i].isFile()) {
System.out.println("文件:" + files[i]);
} else {
System.out.println("目录:" + files[i]);
// System.out.println("目录绝对地址:" + files[i].getAbsolutePath());
getFileList(files[i].getAbsolutePath());
}
}
}
}
更多精彩
赞助商链接