안녕하세요 아즈라엘 입니다.
파일 IO 를 하는 부분에서 파일을 읽고 쓰고 지우는 과정을 합니다.
파일을 지우게 되므로 다시 In/Out Stream 을 생성시켜야 하는데
루프문에서 계속 하거든요..
그래서
try {
if (dos != null) {
dos.close();
dos = null;
dos = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(new File(recordingFile))));
}
} catch (IOException e) {
} catch (NullPointerException e) {
}
이렇게 null 문자로 넣어주어 GC 에게 위임을 하고 새로 new 했더니 안되더군요..
그리하여
dos = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(new File(recordingFile))));
부분을 다른 메서드에서 하니 되는겁니다.
즉
try {
if (dos != null) {
dos.close();
dos = null;
}
} catch (IOException e) {
} catch (NullPointerException e) {
}
여기 까지만 한 메서드에서 하고
나머지 부분은 다음 메서드에서
if(dos == null){
dos = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(new File(recordingFile))));
}
이렇게 해서 처리 하니 되네요..
혹시 이런 경험 있으신가요?
음.. 그런 경험은 없지만..
질문이 있어서 댓글을 달아봅니다.
null값을 넣고 바로 new를 해주는거랑
null을 넣지 않고 close() 후에 바로 new 해주는거랑 차이점이 있나요?
객체를 바로 할당을 해주게 되면 그전의 데이터들은 링크를 잃어버리고 자동으로 GC대상으로 빠지지 않는지...