JFileChooser和Eclipse [英] JFileChooser and eclipse

查看:70
本文介绍了JFileChooser和Eclipse的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种让JFileChooser允许用户从仅包含在eclipse项目的bin文件中的txt文件中进行选择的方法.有没有办法让JFileChooser弹出并显示bin文件夹中驻留的选定数量的txt文件?

I am looking for a way to have JFileChooser allow the user to choose from txt files that are included in the bin file of eclipse project only. Is there a way to have the JFileChooser pop up and display a selected number of txt files that reside with in the bin folder?

推荐答案

您可以参考以下代码,只需指定文件夹/目录的绝对或相对路径

You can refer to the following code, just specify absolute or relative path to your folder/dir

JFileChooser chooser = new JFileChooser();
FileNameExtensionFilter filter = new FileNameExtensionFilter(
    "TXT files", "txt");
chooser.setFileFilter(filter);
chooser.setCurrentDirectory("<YOUR DIR COMES HERE>");
int returnVal = chooser.showOpenDialog(parent);
if(returnVal == JFileChooser.APPROVE_OPTION) {
   System.out.println("You chose to open this file: " +
        chooser.getSelectedFile().getName());
}

JFileChooser

这篇关于JFileChooser和Eclipse的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆