码迷,mamicode.com
首页 > 编程语言 > 详细

java 弹出选择目录框(选择文件夹),获取选择的文件夹路径

时间:2019-09-24 12:09:44      阅读:510      评论:0      收藏:0      [点我收藏+]

标签:ring   tle   echo   new   top   文档   sele   get   tde   

 1 int result = 0;
 2 File file = null;
 3 String path = null;
 4 JFileChooser fileChooser = new JFileChooser();
 5 FileSystemView fsv = FileSystemView.getFileSystemView();  //注意了,这里重要的一句
 6 System.out.println(fsv.getHomeDirectory());                //得到桌面路径
 7 fileChooser.setCurrentDirectory(fsv.getHomeDirectory());
 8 fileChooser.setDialogTitle("请选择要上传的文件...");
 9 fileChooser.setApproveButtonText("确定");
10 fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
11 result = fileChooser.showOpenDialog(chatFrame);
12 if (JFileChooser.APPROVE_OPTION == result) {
13            path=fileChooser.getSelectedFile().getPath();
14            System.out.println("path: "+path);
15    }
16 
17 这是另外一种方法得到桌面路径:
18 File desktop = new File(System.getProperty("user.home")+System.getProperty("file.separator")+"XX");
19 
20 filechooser.setCurrentDirectory(desktop); 
21 
22 我的文档 路径:  fsv.getDefaultDirectory()); 

 

java 弹出选择目录框(选择文件夹),获取选择的文件夹路径

标签:ring   tle   echo   new   top   文档   sele   get   tde   

原文地址:https://www.cnblogs.com/xiaoyue1606bj/p/11577256.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!