final JFileChooser fc = new JFileChooser();
int returnVal = fc.showOpenDialog(this);
if (returnVal == JFileChooser.APPROVE_OPTION) {
String fileName = fc.getSelectedFile().getName();
String path = (new File(fileName)).getAbsolutePath();
}
我得到的绝对路径是项目目录和文件名的串联!
最佳答案
JFileChooser.getSelectedFile()
返回File
对象。
为什么要获取文件名并再次实例化一个新的 File
对象?
你能尝试一下吗:
fc.getSelectedFile().getAbsolutePath();
关于java - JFileChooser 返回错误的文件名?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8350284/