Reputation: 404
Is there a possibility to open a preconfigured directory directly in the JFileChooser opendialog ?
I tried to set some directory with the follow code:
File fn = new File("C://Users//me//Documents//Test");
openFile = new JFileChooser();
openFile.showOpenDialog(f);
openFile.setCurrentDirectory(fn);
fto = openFile.getSelectedFile();
loadFile(openFile.getSelectedFile());
Upvotes: 0
Views: 43
Reputation: 9192
It can go something like this:
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);
Upvotes: 1