Object(Input/Output)Stream은...


[ 다음 글들 ] [ 이어서 글올리기(답하기) ] [ 자바 묻고 답하기 ]

글쓴이 :박찬우 2000년 5월 23일 13:19:29

In Reply to: ObjectOutputStream... posted by 이윤정 on 2000년 5월 23일 09:52:13:

Object(Input/Output)Stream은 객체를 직렬화해서
저장하는 것으로 알고 있습니다.


따라서 writeUTF()등의 메서드를 쓴다해도
저장된 형태는 사람이 그 내용 전부를 완전히
알아볼 형태는 아닙니다.
고유로 다시 해석해낼 수 있도록 나름대로의 저장방식을 사용합니다.


따라서 문자를 읽어들이고 쓰는 것이라면 InputStream은 1바이트 계열이고
Reader는 2바이트 계열의 스트림이므로
이들을 연결시켜 주는 Input(Output)Stream(Reder/Writer)을 쓰면 될 것입니다.


보니까 파일 복사 프로그램이군요.


대충 고쳐보았습니다.




import java.io.*;


public class CopyBytes {
public static void main(String [] args) throws IOException {
File inputFile = new File("sample.txt");
File outputFile = new File("temp.txt");



FileInputStream fin = new FileInputStream(inputFile);
FileOutputStream fout = new FileOutputStream(outputFile);


BufferedReader in = new BufferedReader(new InputStreamReader(fin));
BufferedWriter out = new BufferedWriter(new OutputStreamWriter(fout));



String str;



while ((str = in.readLine()) != null) {
out.write(str); //Writer 클래스에서 상속받은 메서드
out.newLine();
out.flush();
}


fin.close();
fout.close();


in.close();
out.close();
}
}





from NUCHA



다음 글들:



이어서 글올리기(답하기)

이름:
E-Mail:
제목:
내용:
HTML 태그 포함 여부: HTML 문서일 경우 체크
관련 URL(선택):
URL 제목(선택):
관련 이미지 URL:


[ 다음 글들 ] [ 이어서 글올리기(답하기) ] [ 자바 묻고 답하기 ]