File explorer java

不羁的心 提交于 2019-12-06 11:58:18

This snippet allows you to list all files recursivly. You could use the data to populate a JTree see this tutorial

public class Filewalker { 

    public void walk( String path ) { 

        File root = new File( path ); 
        File[] list = root.listFiles(); 

        for ( File f : list ) { 
            if ( f.isDirectory() ) { 
                walk( f.getAbsolutePath() ); 
                System.err.println( "Dir:" + f.getAbsoluteFile() ); 
            } 
            else { 
                System.err.println( "File:" + f.getAbsoluteFile() ); 
            } 
        } 
    } 

    public static void main(String[] args) { 
        Filewalker fw = new Filewalker(); 
        fw.walk("c:\\" ); 
    } 
} 

Perhaps something like this would help you (this is from a quick googling, I don't do GUIs but felt obliged to help):

http://www.java2s.com/Code/Java/Swing-JFC/FileTreewithPopupMenu.htm

trashgod

Empirically, java.awt.FileDialog offers more native look that may suffice. Here's an example that also references a more versatile component, org.netbeans.swing.outline.Outline.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!