DefaultMutableTreeNode 为一个数组textArea 可以为别的这个主要是左边一个树,右边是 textArea 的情况,jsp可以参考一下public void Explorer2(DefaultMutableTreeNode p) //检测目录的最好方法 { p.removeAllChildren(); //关键的修改处,如果没有这一句,就会出现两次或多次加载同一节点的现象 try{ File path = (File)p.getUserObject(); String[] list = path.list(); for(int i = 0; i<list.length;i++) { File NotKnown = new File(path + "\\" + list[i]); if(NotKnown.isFile()) { textArea.append(list[i] + '\n'); tempLeaf = new DefaultMutableTreeNode(NotKnown); tempLeaf.setAllowsChildren(false); p.add(tempLeaf); } else if(NotKnown.isDirectory()) { textArea.append(list[i] + '\n'); tempDir = new DefaultMutableTreeNode(NotKnown); tempDir.setAllowsChildren(true); p.add(tempDir); } } } catch(Exception e) { System.out.println("Error: " + e); } }
解决方案 »
- 新手求救数据库链接问题!!
- 关于数据库查询与网页的问题求教各位
- 这个问题很不解.....
- 生成JSP页的模板如何来做?
- jsp+mysql急问
- 为什么啊,我最亲密的好友就这样离开了人世啊,苍天你没长眼睛啊!
- 谁能给我一个JDBC中涉及到事务回滚的例子,谢谢!
- 服务器报错,重启就没这个错了严重: Error in dependencyCheck java.io.FileNotFoundException:
- 新手学Ajax的一个问题
- Content-Type: application/x-www-form-urlencoded的http请求如何使用流的方式获取param
- 一个mysql查询语句的问题
- tomcat 5.0.19在哪设置站点目录?
请问:
1、取文件的路径用什么函数或方法?
2、list是否将目录下所有文件都放进了list数组中?
3、都需用哪些java包呀??
忘告之,Thanks again.
path.getLastPathComponent();
File f1 = new File(dirname);
if (f1.isDirectory()) {
out.println("Directory of " + dirname);
String s[] = f1.list();
for (int i=0; i < s.length; i++) {
File f = new File(dirname + "/" + s[i]);
if (f.isDirectory()) {
out.println(s[i] + " is a directory");
} else {
out.println(s[i] + " is a file");
}
}
} else {
out.println(dirname + " is not a directory");
}
}