gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 11:07:19 24 4
gpt4 key购买 nike

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

最佳答案

这可以使用 JFileChooser 来完成。 Official Tutorial是最好的起点。

重要步骤是:

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);
}

关于java - 如何在java应用程序中打开文件夹windows?我想在我的应用程序中插入文件 .txt 的路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32806573/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com