如何在java应用程序中打开文件夹窗口?我想在应用程序中插入.txt文件的路径



如何制作一个按钮,可以打开文件夹选项和搜索。txt文件。我想通过打开窗口插入路径(例如:c:/documents)如果文件夹选项。所以我的应用程序的用户只需点击它,而不是在字段文本中键入它。顺便说一下,我使用netbeans作为我的IDE。请帮帮我。谢谢你。

这可以用JFileChooser完成。官方教程是最好的起点。

重要步骤如下:

JFileChooser fc = new JFileChooser();
int returnVal = fc.showOpenDialog(this);
if (returnVal == JFileChooser.APPROVE_OPTION) {
    File file = fc.getSelectedFile();
    //This is where a real application would open the file.
    log.append("Opening: " + file.getName() + "." + newline);
} else {
    log.append("Open command cancelled by user." + newline);
}

最新更新