[英]How to open directly a directory(location) with JFileChooser?
是否可以直接在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());
它可以像这样:
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);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.