How to use JFileChooser to find a file location

前端 未结 3 1207
春和景丽
春和景丽 2021-01-16 01:38

Is there a method that i can use to simply find a file location? I\'m trying allow the user to choose a file and open it, but I have to have the JFileChooser just choose the

3条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-16 02:16

    chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    
    // You can use 
    // chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);  too
    
    File file = chooser.getSelectedFile();
    String fullPath = file.getAbsolutePath();
    

    Then Pass the String to the other method.

提交回复
热议问题