for(int i=0;i<files.length;i++) { System.out.println(files[i]); }输出: 我的电脑 网上邻居 C:\Documents and Settings\dragon\My Documents C:\Documents and Settings\dragon\Desktop\DevNotes检查细则模板.xls C:\Documents and Settings\dragon\Desktop\experience.doc C:\Documents and Settings\dragon\Desktop\experiences.doc C:\Documents and Settings\dragon\Desktop\j2sdk-1_4_2_10-windows-i586-p.exe C:\Documents and Settings\dragon\Desktop\sources C:\Documents and Settings\dragon\Desktop\sources.zip C:\Documents and Settings\dragon\Desktop\tame.zip C:\Documents and Settings\dragon\Desktop\Test and JTreeTable.rar C:\Documents and Settings\dragon\Desktop\The Java Developers Almanac 1.4 C:\Documents and Settings\dragon\Desktop\The Java Developers Almanac 1.4.zip C:\Documents and Settings\dragon\Desktop\快捷方式 到 eclipse.lnk C:\Documents and Settings\dragon\Desktop\瑞星卡卡上网安全助手.lnk C:\Documents and Settings\dragon\Desktop\金山词霸 2005.lnk C:\Documents and Settings\All Users\Desktop\AvRack.lnk C:\Documents and Settings\All Users\Desktop\DAEMON Tools.lnk C:\Documents and Settings\All Users\Desktop\Java Web Start.lnk C:\Documents and Settings\All Users\Desktop\Skype.lnk C:\Documents and Settings\All Users\Desktop\瑞星杀毒软件.lnk谢谢gtlang78() ,你这个我觉得已经差不多了,但是可能因为我的电脑和网上邻居不是一个直接路径,我暂时还没有搞定,再过段时间jf。
if(!file.exit()){
return;
}
File fs[]=file.listFiles();
for(int i=0;i<fs.length;i++){
File f=fs[i];
if(f.isDirectory()){
printFileList(f);
}else{
System.out.println(f.getName());
}
}
}简单的样例代码,没有在编译器下写,应该有语法错误,你看懂就可以了
把文件遍历出来,放到JTree上你自己就可以实现了吧
import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.StringReader;
import java.net.URI;import org.luyang.lang.RegularExpressions;public class FilePathRead {
public static void main(String[] args){
FilePathRead t = new FilePathRead();
t.find(new File("C:\\j2sdk1.4.2_10"));
}
public void find(File f){
if(f.isDirectory()){
File[] fileList = f.listFiles();
for(int i = 0; i < fileList.length; i++){
find(fileList[i]);
}
}else{
if(f.getName().endsWith(".java"))
System.out.println(f.getAbsolutePath());
}
}
}
但是可能还是误会了,我要的不是怎么去实现JTree,我只是不知道怎么从系统根目录开始
比方说这样子 new File("d:\\") 我已经可以从d:开始浏览
但是要怎样才能从系统根目录也就是D:的上一级目录开始浏览呢?望高手们不吝赐教,感激澪涕。
System.out.println(files[i]);
}
会输出:
A:\
C:\
D:\
E:\
F:\
输出的是一个同级列表
这个是从桌面开始的
难道就没有一个路径是指向之上的吗?
FileSystemView.getFileSystemView().getFiles(), 这个方法可以从刚才的 getRoots()得到的桌面目录开始,得到"我的电脑", "我的文档", "网上邻居"等等, 然后递归的调用这个方法就可以从"我的电脑"得到 A: C: D: 等等.
for(int i=0;i<files.length;i++)
{
System.out.println(files[i]);
}输出:
我的电脑
网上邻居
C:\Documents and Settings\dragon\My Documents
C:\Documents and Settings\dragon\Desktop\DevNotes检查细则模板.xls
C:\Documents and Settings\dragon\Desktop\experience.doc
C:\Documents and Settings\dragon\Desktop\experiences.doc
C:\Documents and Settings\dragon\Desktop\j2sdk-1_4_2_10-windows-i586-p.exe
C:\Documents and Settings\dragon\Desktop\sources
C:\Documents and Settings\dragon\Desktop\sources.zip
C:\Documents and Settings\dragon\Desktop\tame.zip
C:\Documents and Settings\dragon\Desktop\Test and JTreeTable.rar
C:\Documents and Settings\dragon\Desktop\The Java Developers Almanac 1.4
C:\Documents and Settings\dragon\Desktop\The Java Developers Almanac 1.4.zip
C:\Documents and Settings\dragon\Desktop\快捷方式 到 eclipse.lnk
C:\Documents and Settings\dragon\Desktop\瑞星卡卡上网安全助手.lnk
C:\Documents and Settings\dragon\Desktop\金山词霸 2005.lnk
C:\Documents and Settings\All Users\Desktop\AvRack.lnk
C:\Documents and Settings\All Users\Desktop\DAEMON Tools.lnk
C:\Documents and Settings\All Users\Desktop\Java Web Start.lnk
C:\Documents and Settings\All Users\Desktop\Skype.lnk
C:\Documents and Settings\All Users\Desktop\瑞星杀毒软件.lnk谢谢gtlang78() ,你这个我觉得已经差不多了,但是可能因为我的电脑和网上邻居不是一个直接路径,我暂时还没有搞定,再过段时间jf。