1. 객체

    1. FileInputStream - 파일로 부터 일어오기
    2. FileOutputStream - 파일에 쓸수 있게 해줌
  2. read() 메소드

    1. 읽어들일 것이 존재한다면 양수 리턴
    2. 읽어들일 것이 없다면 -1을 리턴 함.

    byte 단위 입출력기 코드

    public class ByteIOExam1 {
            public static void main(String[] args){
                FileInputStream fis = null;
                FileOutputStream fos = null;
                try {
                    fis = new FileInputStream("src/javaIO/exam/ByteExam1.java");
                    fos = new FileOutputStream("byte.txt");
    
                    int readData = -1;
                    while((readData = fis.read())!= -1){
                        fos.write(readData);
                    }
                } catch (Exception e) {
    // TODO Auto-generated catch blocke.printStackTrace();
                }finally{
                    try {
                        fos.close();
                    } catch (IOException e) {
    // TODO Auto-generated catch blocke.printStackTrace();
                    }
                    try {
                        fis.close();
                    } catch (IOException e) {
    // TODO Auto-generated catch blocke.printStackTrace();
                    }
                }
            }
        }
    

    fos.write(n) : 저장된 int 값의 가장 낮은 1바이트 파일에 쓰임.

    int n = 65; // ASCII 코드에서 'A'에 해당하는 값 fos.write(n); // 파일에 'A'를 씁니다.