如何使用jfilechooser从java中的文件名数组中获取多个文件选择的绝对路径

如何使用jfilechooser从java中的文件名数组中获取多个文件选择的绝对路径,java,jfilechooser,Java,Jfilechooser,下面是附加多个文件的源代码 public void doAttachFile(){ try { JFileChooser fileChooser = new JFileChooser(); fileChooser.setMultiSelectionEnabled(true); int selection = fileChooser.showOpenDialog(null); if(selection == JFileChooser

下面是附加多个文件的源代码

public void doAttachFile(){
 try {
        JFileChooser fileChooser = new JFileChooser();
        fileChooser.setMultiSelectionEnabled(true);
        int selection = fileChooser.showOpenDialog(null);
        if(selection == JFileChooser.APPROVE_OPTION){// if open button is clicked
            File [] selectedFile = fileChooser.getSelectedFiles();
        }
}catch(Exception e){
     JOptionPane.showMessageDialog(this,"Error attaching files\n"+e.toString,"Error",JOptionPane.ERROR_MESSAGE);
}
}


如何从数组中获取所选文件的绝对路径?

您可以遍历每个
文件
对象,并获取文件的绝对路径,如下所示:

File [] selectedFile = fileChooser.getSelectedFiles();
for(File file : selectedFile) {
    String absolutePath = file.getAbsolutePath(); //gives the absolute path
    System.out.println(absolutePath);
}

将尝试并给出反馈@javaguy将尝试并给出反馈@javaguy