자바 파일 입출력 질문드려요
글쓴이: revol2236 / 작성시간: 화, 2011/11/22 - 11:37오후
제가 만들고 싶은 부분은 기존 파일에 있는 부분에 덧붙여서 다른 내용을 저장하는 것인데요
예를들어 data.txt 라는 텍스트 파일에
kldp.org 라는 내용이 써져있다면 다시한번 프로그램을 실행시킬때는
kldp.org 라는 내용아래에
linux 라는 문자가 추가 되는 형식 입니다,, 그런데 어쩐지 컴파일은 되는데 실행할때
오류가 뜨네요,,
문제가 뭔지 알려주시면 감사하겠습니다,,,
import java.util.StringTokenizer; import java.io.*; class JAVA_File { public static void main(String[] args){ try{ File imsifile = new File("./file_pra/data2.txt"); String s = "캐릭터 정보"; String k; BufferedReader an = new BufferedReader(new FileReader(imsifile)); File filename = new File("./file_pra/data.txt"); BufferedReader ow = new BufferedReader(new FileReader(filename)); System.out.println(ow.readLine()); k=ow.readLine(); if(k==""){ BufferedWriter wr = new BufferedWriter(new FileWriter("./file_pra/data.txt")); System.out.println(ow.readLine()); wr.write(s); wr.newLine(); wr.close(); } else{ BufferedWriter ir = new BufferedWriter(new FileWriter(imsifile)); do{ ir.write(ow.readLine()); ir.newLine(); }while(ow.readLine()!=null); ir.write(s); ir.close(); BufferedWriter wr = new BufferedWriter(new FileWriter("./file_pra/data.txt")); do{ wr.write(an.readLine()); wr.newLine(); }while(an.readLine()!=null); wr.close(); } }catch(Exception ex){ ex.printStackTrace(); } } }
Forums:
try catch 의 exception의 call
try catch 의 exception의 call stack 및 에러 메시지를 잘 확인해 보세요.
거기에 힌트가 있습니다.
예 완료했습니다
위엣분 코드도 감사했습니다만
혼자서 여차여차 하다보니까 해결이 됬습니다,,
저는 생성자 호출 부분에서 문제가 있을줄 알았는데
어이없게도 반복문을 잘못쓰는 바람에
readLine() 할때마다 여기에 계속 null 값이 들어 가고 있었더군요 -ㅡ-;;;
관심가져 주셔서 감사합니다 !!!
============================================
비가오면 사람들은 눈물흘리고
그빗물에 흘러내린 눈물감추고
댓글 달기