private
static
String
ChooseFolder(
)
{
JFileChooser
fc = new
JFileChooser
(
)
;
JList
list = new
JList
(
)
;
fc.setFileSelectionMode
(
JFileChooser
.DIRECTORIES_ONLY
)
;
if
(
JFileChooser
.APPROVE_OPTION
== fc.showOpenDialog
(
list)
)
{
File
file = fc.getSelectedFile
(
)
;
return
file.getPath
(
)
;
}
return
""
;
}
private
static
String
ChooseFile(
)
{
JFileChooser
fc = new
JFileChooser
(
)
;
JList
list = new
JList
(
)
;
fc.setFileSelectionMode
(
JFileChooser
.FILES_ONLY
)
;
if
(
JFileChooser
.APPROVE_OPTION
== fc.showOpenDialog
(
list)
)
{
File
file = fc.getSelectedFile
(
)
;
return
file.getPath
(
)
;
}
return
""
;
}
File/Folder Chooser 选择
最新推荐文章于 2025-11-25 09:33:22 发布
本文介绍了一个简单的Java程序,该程序使用Swing库中的JFileChooser组件来让用户选择文件夹或文件,并返回所选路径。这对于需要用户交互选择文件或目录的应用场景非常实用。
2893

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



