java 写的文件浏览器

2016-02-19 16:29 1 1 收藏

今天天气好晴朗处处好风光,好天气好开始,图老师又来和大家分享啦。下面给大家推荐java 写的文件浏览器,希望大家看完后也有个好心情,快快行动吧!

【 tulaoshi.com - 编程语言 】

//------------------------------------------------------------
// 编译下边的类,并运行无需任何参数
//-----------------------------------------------------------
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:n+++++++++++++++++++++++++++++++++");
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;itemp_list.length;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();
}
}

来源:https://www.tulaoshi.com/n/20160219/1612268.html

延伸阅读
标签: 浏览器
怎样清理360浏览器缓存文件   1、打开浏览器,找到工具栏。 2、选择清楚上网痕迹 3、选择需要清除的缓存文件和使用记录 4.清除完毕。浏览器是不是感觉运行快了。
导出UC浏览器下载文件   首先打开UC浏览器,然后找到下载管理,然后选择已下载。 然后看到了以前曾经下载的,我们长按它们,重命名,把后缀名改为.mp3确定。 然后长按,导出至"音乐+视频"。 然后我们手机连接电脑,找到Unknown Artist这个文件夹,路径为 计算机Windows phonePhoneMusic ...
标签: 浏览器
阿云浏览器如何打开文件   当您需要打开某些文件时,您可以进行如下操作:点击云logo 页面和标签打开,然后选择您需要打开的文件即可,如下图所示: 或者您也可以直接使用快捷键:Ctrl+O来打开文件。 在阿云浏览器中,可以打开的文件类型包括:HTML Files、Text Files、GIF Files、JPEG Files、AIFF Files、AU Files等...
标签: 浏览器
IE浏览器视频缓存文件在哪   1、打开自己电脑上的浏览器 2、在最上面的框里选择工具 3、选择 internet 选项 4、点击设置 5、查看文件 可以通过查找大小文件,将大的文件放在上面,一般视频都比文件大很多,这样就找出来了。
百度浏览器设置为默认浏览器方法来啦~百度浏览器是大家经常使用的一款浏览器,那么怎么将百度浏览器设置成默认浏览器呢?下文小编就为大家带来百度浏览器设置为默认浏览器的方法,一起去看下吧。 百度浏览器下载地址: 百度浏览器2015官方下载电脑版 百度浏览器设置为默认浏览器方法: 1、打开...

经验教程

785

收藏

61
微博分享 QQ分享 QQ空间 手机页面 收藏网站 回到头部