먼저 당신은 당신의 더 나은 옵션이 choser.showOpenDialog 또는 showSaveDialog
이 저장 대화 상자가 그것이 존재하지 않는 파일이 될 수 지정된 경로에있는 이름을 선택하게되지만, 개방은 항상 받아
이 선택되어 있는지 확인합니다 file .. 파일이 존재하는지 확인하기 위해 file.exists()를 안전하게 추가 할 수 있습니다. 또한 등등의 버튼 .. 대화 .. 텍스트를 변경할 수 있습니다
JFileChooser chooser = new JFileChooser();
chooser.setApproveButtonText("Save");
int result = chooser.showOpenDialog(null);
if(result == JFileChooser.APPROVE_OPTION){
File selection = chooser.getSelectedFile();
//verify if file exists
if(selection.exists()){
//you can continue the code here or call the next method or just use !exists and behavior for wrong file
}else{
//System.exit(0), show alert.. etc
}
}
는 문자열처럼 힌트를 추가 할 수 있도록 할 것 setDialogTitle 방법을 사용하여 Eng.Fouad의 답변이지만 위에 링크 된 showDialog 메소드를 사용하여 저장 버튼 레이블을 "저장"으로 유지하십시오. http://docs.oracle.com/javase/6/docs/api/javax/swing/JFileChooser.html#setDialogTitle%28java.lang.String%29 –