import java.io.FileInputStream;
import java.io.FileOutputStream;
public class Test3 {
public static void main(String[] args) {
try {
// 파일 저장(없으면 만들고, 있으면 지우고 만듬)
// FileOutputStream : 파일출력바이트 스트림
FileOutputStream fos = new FileOutputStream("test.txt");
int ch;
// 단, 엔터를 누르지 않으면 안됨
System.out.print("문자열[종료 ctrl+z]?");
while ((ch = System.in.read()) != -1) {
fos.write(ch);
}
fos.close();
// 파일이 없으면 FileNotFoundException이 발생
FileInputStream fis = new FileInputStream("test.txt");
System.out.println("파일에 저장된 내용....");
while ((ch = fis.read()) != -1) {
System.out.write(ch);
}
fis.close();
} catch (Exception e) {
System.out.println(e.toString());
}
}
}
'자바 DB 연동 > 입출력 스트림' 카테고리의 다른 글
File 클래스 - 폴더만들기, 파일정보구하기 (0) | 2013.06.14 |
---|---|
flush 메소드 (0) | 2013.06.14 |
FileOutputStream / FileInputStream (0) | 2013.06.14 |
InputStreamReader (1) | 2013.06.14 |
System.in.read() (0) | 2013.06.14 |