2016-11-05 3 views
0

JFileChooser opendialogにあらかじめ設定されたディレクトリを直接開くことはできますか?JFileChooserでディレクトリ(場所)を直接開く方法は?

私は次のコードでいくつかのディレクトリを設定しようとしました:

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

の可能な複製を[どのように私は、現在のディレクトリ内のJFileChooserが開いて作るのですかユーザーは?](http://stackoverflow.com/questions/21844188/how-do-i-make-jfilechooser-open-in-the-current-directory-the-user-is-in) –

+0

ありがとう、またしかし、私は以下のような解決策を探していました。それでも、私はそれを考慮する。 –

答えて

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); 
関連する問題