【问题标题】:How to open directly a directory(location) with JFileChooser?如何使用 JFileChooser 直接打开目录(位置)?
【发布时间】:2017-03-19 12:17:55
【问题描述】:

是否可以直接在 JFileChooser opendialog 中打开预先配置的目录?

我尝试使用以下代码设置一些目录:

   File fn = new File("C://Users//me//Documents//Test");
   openFile = new JFileChooser();
   openFile.showOpenDialog(f);
   openFile.setCurrentDirectory(fn);
   fto = openFile.getSelectedFile();
   loadFile(openFile.getSelectedFile());

【问题讨论】:

标签: java directory jfilechooser


【解决方案1】:

它可以是这样的:

String startPath = "C://Users//me//Documents//Test";
JFileChooser openFile = new JFileChooser(new File(startPath));
openFile.showOpenDialog(null);

File fileChoosen = openFile.getSelectedFile();
String fileName = openFile.getSelectedFile().getName();
String filePathAndName = openFile.getSelectedFile().getPath();

//Do what you want with the variables...
System.out.println(fileName);
System.out.println(filePathAndName);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-12-21
    • 2014-02-24
    • 2014-07-27
    • 2021-02-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多