加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

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

发布时间:2020-12-15 07:39:44 所属栏目:Java 来源:网络整理
导读: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(
 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()); 

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读