Get the path of a directory using JFileChooser

后端 未结 3 1018
甜味超标
甜味超标 2020-12-19 05:19

How can I get the absolute path of a directory using JFileChooser, just selecting the directory?

3条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-19 05:54

    Try:

    chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    
    File file = chooser.getSelectedFile();
    String fullPath = file.getAbsolutePath();
    
    System.out.println(fullPath);
    

    fullPath gives you the required Absolute path of the Selected directory

提交回复
热议问题