package CHAPTER13;

import java.io.FileOutputStream; // 파일 출력 스트림 클래스를 가져옴
import java.io.IOException; // 입출력 예외 처리를 위한 IOException 가져옴

public class C13_02_ByteOutputStreamExample { // 바이트 출력 스트림 예제 클래스
    public static void main(String[] args) {
        // try-with-resources 문을 사용하여 FileOutputStream 객체를 자동으로 닫도록 설정
        try (FileOutputStream fos = new FileOutputStream("output.txt")) { // "output.txt" 파일을 쓰기 위한 파일 출력 스트림 열기
            String message = "Hello, Byte Stream!"; // 파일에 저장할 문자열 선언
            fos.write(message.getBytes()); // 문자열을 바이트 배열로 변환하여 파일에 기록
            System.out.println("파일에 데이터가 기록되었습니다."); // 데이터 기록 완료 메시지 출력
        } catch (IOException e) { // 파일 입출력 예외 발생 시 처리
            e.printStackTrace(); // 예외 정보를 출력
        }
    }
}
