<%-- JSP全站自动生成HTML下载新闻系统 V3.1 作者:JSP天空网站长 曹进 QQ:173241393 --%> java 写的文件浏览器
 
用户名:
密码:
终身会员
  首页 网络文摘 技术专题 下载中心 JSP培训 公司产品 JSP虚拟主机 技术论坛 会员 JSP免费空间  
  技术文摘: JSP基础 | JSP高级 | JSP环境 | JAVA基础 | JAVA高级 | JAVA工具 | JAVA数据库 | WEB框架 | XML相关 | JAVA考试 | J2EE相关 | J2ME相关 |
  视频下载: 程序设计数据库相关教程计算机基础教程图形图像网络技术网络安全时空书库EasyShop虚拟主机JSP培训技术论坛
  书籍教程: JSP教程Java教程图像软件XML教程数据库教程网页教程工具软件服务器相关ASP教程PHP教程CGI教程.NET教程
  代码下载: ASP代码下载JSP代码下载PHP代码下载CGI代码下载Flash代码C/C++/VCPowerBuilderDelphiVisualBasicVisualFoxpro
您的位置: 首页 -> 文章分类 -> JAVA高级 -> java 写的文件浏览器
 文摘搜索
 
 文摘资源分类
 
 文摘总排行榜TOP10
 
 最新更新文摘TOP10
 

java 写的文件浏览器

[来源]www.jspsky.com管理员   [作者]网络文摘   [时间]2005-4-7
推荐等级: 点击:
//------------------------------------------------------------
// 编译下边的类,并运行无需任何参数
//-----------------------------------------------------------
package com.swing.tree;
import java.io.*;
import java.util.*;
import javax.swing.tree.*;
public class file_path_obj
{
private String dir_tree="";
private File temp;
DefaultMutableTreeNode root=null;
public DefaultMutableTreeNode getPath_Obj()
{
if(this.root==null)
return new DefaultMutableTreeNode("null NODE");
return this.root;
}
public file_path_obj(String path)
{
try{
root= this.set(path);
}catch(Exception e)
{
System.out.println("tree error: +++++++++++++++++++++++++++++++++");
e.printStackTrace();
}}

public DefaultMutableTreeNode set(String dir) throws Exception //第归遍历文件甲
{
File[] temp_list = null;
if(new File(dir).exists()==false)
throw new Exception("file name is null");
DefaultMutableTreeNode tempNode;
temp = new File(dir);
if(temp.isFile())
{
return new DefaultMutableTreeNode(temp.getAbsolutePath());
}
temp_list = temp.listFiles();
tempNode = new DefaultMutableTreeNode(temp.getAbsolutePath());
//设置上级菜单的名字
if(temp_list.length==0) return new DefaultMutableTreeNode(temp.getAbsolutePath());
for(int i=0;i {
if(temp_list[i].isDirectory())
{
System.out.println("the file is:"+temp_list[i].getAbsolutePath());
tempNode.add(this.set(temp_list[i].getAbsolutePath()));
}
else
tempNode.add(new DefaultMutableTreeNode(temp_list[i].getAbsolutePath()));
}
return tempNode;
}
}


//------------------------------------------------------------
// 编译下边的类,并运行无需任何参数
//-----------------------------------------------------------
package com.tree;
import java.io.*;
import java.awt.*;
import javax.swing.*;
import javax.swing.tree.*;
import com.swing.tree.*;

/** Example tree built out of DefaultMutableTreeNodes.
* ycj
*/
public class pathTree extends JFrame {
public static void main(String[] args) {
try
{
BufferedReader bin = null;
bin = new java.io.BufferedReader(new InputStreamReader(System.in));
String path="";
File temp = null;
System.out.print("输入要显示的文件路径");
while(bin!=null)
{
path = bin.readLine();
if(path==null)
{
System.out.println("请输入合法的文件路径");
continue;
}
temp = new File(path);
if(temp.exists()==false||temp.isFile())
System.out.println("请输入正确的文件路径");
else
{new pathTree(path);
break;
}
}
}catch(Exception e)
{ e.printStackTrace(); }
}
public pathTree(String path)
{
super("Creating a Simple JTree");
WindowUtilities.setNativeLookAndFeel();//set the UIManager
addWindowListener(new ExitListener());
Container content = getContentPane();
file_path_obj obj = new file_path_obj(path);
System.out.println(obj.getPath_Obj());
JTree tree = new JTree(obj.getPath_Obj());//MAKE A TREE
Cursor cor = new Cursor(Cursor.HAND_CURSOR);
tree.setCursor(cor);
content.setLayout(new FlowLayout());
JPanel jp1 = new JPanel(new BorderLayout());
JPanel jp2 = new JPanel(new BorderLayout());
content.add(jp1);
content.add(jp2);
content.add(new JScrollPane(tree), BorderLayout.CENTER);
setSize(275, 500);
setVisible(true);
this.pack();
}
}
[收藏][打印][关闭]
在线咨询服务 在线咨询服务 在线咨询服务 在线咨询服务
Copyright©2005-2006陕西思远数码科技有限责任公司 服务电话:029-88212987 传真:029-88278265 售后服务QQ:173241393
地址:陕西省西安市吉祥路186号太白新苑C座2104 陕ICP备05004508号