既然已经在使用Java,那么就使用JFileChooser。注意事项:这是一个Swing小部件
它可以在Mac和Windows上运行,但看起来可能有点不同
使用Swing可能会有点令人沮丧(但是任何GUI工具包也会如此,所以这是一个wash)
不需要任何痛苦的安装,只需创建一个.jar文件并分发它
下面是文档页面上给出的示例:
JFileChooser为用户提供了一个简单的选择文件的机制。有关使用JFileChooser的信息,请参阅Java教程中的How to Use File Chooser。在
下面是链接文档页面上给出的代码示例:The following code pops up a file chooser for the user's home
directory that sees only .jpg and .gif images:JFileChooser chooser = new JFileChooser();
FileNameExtensionFilter filter = new FileNameExtensionFilter(
"JPG & GIF Images", "jpg", "gif");
chooser.setFileFilter(filter);
int returnVal = chooser.showOpenDialog(parent);
if(returnVal == JFileChooser.APPROVE_OPTION) {
System.out.println("You chose to open this file: " +
chooser.getSelectedFile().getName());
}
本文介绍如何在Java中使用JFileChooser组件来实现文件选择功能。通过一个示例代码展示了如何设置文件过滤器来仅显示特定类型的文件,并获取用户选择的文件。
4万+

被折叠的 条评论
为什么被折叠?



