2013년 7월 1일 월요일

(130701) 6일차 outputStreamTest.java (File 입력 테스트 - a.txt)

 - 소스
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.OutputStream;

public class outputStreamTest {

public static void main(String[] args) {
OutputStream os = System.out;

try{
File f = new File("a.txt");

// 버퍼에 데이터를 쓴다.
FileWriter fw = new FileWriter(f); // 한글을 지원해줌
// FileWriter fw = new FileWriter(f, true); // 이렇게 쓰면 txt 파일에 반복해서 써진다.
fw.flush(); // 버퍼에 데이터를 모두 쓰지 않아도 강제로 출력
fw.write("안녕하세요");
fw.close(); // 메모리를 효율적으로 사용하기 위해 사용

os.write((int)('c'));
} catch (IOException e){
e.printStackTrace();
}
}
}


 - 결과