0

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());
loadP
  • 404
  • 1
  • 4
  • 15
  • Possible duplicate of [How do I make JFileChooser open in the current directory the user is in?](http://stackoverflow.com/questions/21844188/how-do-i-make-jfilechooser-open-in-the-current-directory-the-user-is-in) – Coder ACJHP Nov 05 '16 at 21:48
  • Thanks, also useful, however I was looking for a solution like the below. Nonetheless I will consider it. – loadP Nov 06 '16 at 11:41

1 Answers1

1

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);
DevilsHnd - 退職した
  • 8,739
  • 2
  • 19
  • 22