如何列出某个目录下的所有文件
解决方案 »
- 急!!!急!!提交的东西放到了svn://127.0.0.1的什么地方?
- 【求助】这个代码为什么列找不到数据库(Column not found)
- 关于文字样式的问题
- 用正则表达式如何查找下面的字符串?
- 5个星星啦.......散分.................
- 初学JAVA,问题01!
- 特急!!!!!!请看下面的代码为什么再Tomcat3.2下好使,再Tomcat4.0下不好使
- 对ResultSet的previous()操作为什么回不去上一行,急救???
- 关于classloader的一个问题
- java里toString方法到底有什么作用呀?
- 请问这两个类是在什么软件包中,在哪里能下载到啊org.apache.callback.CallbackPortType,ServerPortType
- 如何设置JButton可见不可用
楼主【FEIFEI12345678】截止到2008-07-07 13:25:23的历史汇总数据(不包括此帖):
发帖的总数量:10 发帖的总分数:170
结贴的总数量:6 结贴的总分数:100
无满意结贴数:0 无满意结贴分:0
未结的帖子数:4 未结的总分数:70
结贴的百分比:60.00 % 结分的百分比:58.82 %
无满意结贴率:0.00 % 无满意结分率:0.00 %
楼主加油
static void getDir(String strPath) throws Exception {
try {
File f = new File(strPath);
if (f.isDirectory()) {
File[] fList = f.listFiles();
for (int j = 0; j < fList.length; j++) {
if (fList[j].isDirectory()) {
System.out.println(fList[j].getPath());
getDir(fList[j].getPath()); // 在getDir函数里面又调用了getDir函数本身
}
}
for (int j = 0; j < fList.length; j++) { if (fList[j].isFile()) {
System.out.println(fList[j].getPath());
} }
}
} catch (Exception e) {
System.out.println("Error: " + e);
} } public static void main(String[] args) {
String strPath = "C:\\Documents and Settings\\All Users\\Documents\\My Music"; System.out.println(strPath); try {
getDir(strPath);
} catch (Exception e) { }
}
}
if ((fs == null) || (fs.length <= 0)) {
System.out.println("空文件夹");
return;
}
for(String s:fs){
System.out.println(s);
}
String[] fs=new File(localRoot).list();
if ((fs == null) || (fs.length <= 0)) {
System.out.println("空文件夹");
return;
}
for(String s:fs){
System.out.println(s);
}
try {
File[] fList = new File(strPath).listFiles();
if ((fList == null) || (fList.length <= 0)) {
System.out.println("空文件夹");
return;
}else{
for(File s:fList){
System.out.println(s.getPath());
getAllDirectoryAndFile(s.getPath());
}
}
} catch (Exception e) {
e.printStackTrace();
}
}