JFileChooser에서 절대 경로명을 textField에 보여주는방법
안다미로
2023.04.01
search.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
JFileChooser fc = new JFileChooser();
fc.showOpenDialog(new JFrame());
File fileName = fc.getSelectedFile().getAbsoluteFile();
txt3.setText(fileName.getName());
}
});
search버튼을 누르면 파일을 찾은후 확인을 누르면 textField에 절대경로가 다 보이게 하려고 하는데
fileName.getName()을 하면 파일의 절대 경로가 아닌 파일명만 텍스트자리에 나타나게 됩니다.
오떻게 하면 절대 경로명이 다 나타날 수 있게 할 수 있을까요?
-
제철
File이 나오면.. getPath()나 getAbsoultePath()를 사용하시고, 더 정확하게 얻어 내고 싶다면 getCanonicalPath()를 얻어 내면 됩니다. ㅎ
-
봄여울
getPath()