파일을 만들고 사용자의 입력을 저장하는이 코드가 있지만 덮어 쓰기를 유지하고 사용자가 제공 한 각 항목을 저장하려고합니다. 어떻게해야합니까?자바 파일 쓰기는 덮어 쓰기가 아닌 추가가 필요합니까?
File file = new File("info.txt");
BufferedWriter output = null;
try {
output = new BufferedWriter(new FileWriter(file));
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
try {
output.write("Users pick: " + myint+ "\t");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
output.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//file writer
왜 3x 시도 잡을까요? – MGorgon
... 첫 번째 try 블록의 문이 예외를 throw하면 다음 try 블록이 NullPointerException을 throw합니다 .-) – nrainer