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

가능한 복제하려면 사용자가 있습니까?] (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); 
나는 현재 디렉토리에 JFileChooser를 열어 어떻게해야합니까 [의