zoukankan      html  css  js  c++  java
  • 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());                //得到桌面路径
     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()); 
  • 相关阅读:
    SLA打印机之打印机介绍
    SLA打印机之Slc文件解析
    Rayland-FDM打印机C200介绍
    Android 关机和重启
    AGVS调度系统 控制协议
    AGV 控制协议
    Android wechat 分享
    Android wechat 支付
    Android TimeoutExceptions及 wakelock
    flex 兼容性写法
  • 原文地址:https://www.cnblogs.com/xiaoyue1606bj/p/11577256.html
Copyright © 2011-2022 走看看