728x90
반응형
package chap15;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
/*
* FileOutputStream 예제 : 파일에 데이터를 저장
* 파일이 존재하지 않으면 파일 생성
* 파일이 존재하면 기존 파일 수정
* void write(int data) : 1바이트씩 출력
* void write(byte[] buf) : buf의 내용을 출력
* void write(byte[] buf, int start, int len) :
* buf의 start 인덱스의 내용부터 len 만큼 내용을 출력
*/
public class FileOutputStreamEx1 {
public static void main(String[] args) throws IOException {
System.out.println("out.txt 파일에 출력하기");
FileOutputStream fos = new FileOutputStream("out.txt");
fos.write('1');fos.write('2');fos.write('3');
fos.write('a');fos.write('b');fos.write('c');
fos.write('가');fos.write('나');fos.write('다');
byte[] buf = "\n반갑습니다. FileOutputStream예제입니다.".getBytes();
fos.write(buf);
fos.write(buf,4,6);
}
}
728x90
반응형
'study > Java' 카테고리의 다른 글
[Java] 36. IO Exam1 (0) | 2022.04.01 |
---|---|
[Java] 36. IO 출력스트림 (FileWriter) (0) | 2022.04.01 |
[Java] 36. IO 입력스트림 (FileReader) (0) | 2022.04.01 |
[Java] 36. IO 입력스트림 (FileInputStream) (0) | 2022.04.01 |
[Java] 36. IO (Runtime.getRuntime, exec) (0) | 2022.04.01 |