文件浏览器 java
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2938942/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
File explorer java
提问by Studer
I'd like to have some kind of file browser like Windows Explorer inside a Java Application.
我想在 Java 应用程序中使用某种文件浏览器,例如 Windows 资源管理器。
I just want something that's able to list file inside a folder recursively.
我只想要一些能够递归列出文件夹内文件的东西。
Is there a simple way to do this ?
有没有一种简单的方法可以做到这一点?
I already tried to use JFileChooser but it's not what I want.
我已经尝试使用 JFileChooser 但这不是我想要的。
采纳答案by stacker
This snippet allows you to list all files recursivly. You could use the data to populate a JTree see this tutorial
此代码段允许您递归地列出所有文件。您可以使用数据来填充 JTree,请参阅本教程
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:\" );
}
}
回答by whaley
Perhaps something like this would help you (this is from a quick googling, I don't do GUIs but felt obliged to help):
也许这样的事情会帮助你(这是通过快速谷歌搜索,我不做 GUI,但觉得有必要提供帮助):
http://www.java2s.com/Code/Java/Swing-JFC/FileTreewithPopupMenu.htm
http://www.java2s.com/Code/Java/Swing-JFC/FileTreewithPopupMenu.htm
回答by trashgod
Empirically, java.awt.FileDialog
offers more native look that may suffice. Here's an examplethat also references a more versatile component, org.netbeans.swing.outline.Outline
.
根据经验,java.awt.FileDialog
提供更多的原生外观可能就足够了。这是一个示例,该示例还引用了一个更通用的组件org.netbeans.swing.outline.Outline
.