loading

새소식

Framework/Springboot

[Springboot] 스프링부트 입출력 스트림

  • -
728x90
반응형

▶ 입출력 스트림의 종류

1. Byte Stream : 그림, 멀티미디어 등의 바이너리 데이터 읽고 쓰기
  => InputStream 과 OutputStream 을 주로 사용.

package prac01;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;

public class ByteStream {
    public static void main(String[] args) throws IOException {
        InputStream in = new FileInputStream("a.bin");
        byte[] buffer = new byte[1000];
        while(true) {
            int letter = in.read(buffer);
            if(letter == -1) break;
            System.out.println((char) letter);
        }
    }

}
package prac01;

import java.io.*;

public class ByteStream2 {
    public static void main(String[] args) throws IOException {
        InputStream in = new FileInputStream("a.bin");
        InputStreamReader isr = new InputStreamReader(in);
        BufferedReader reader = new BufferedReader(isr);
        while(true){
            String data = reader.readLine();
            // 참조 자료형의 빈 값 = null //
            if (data == null) break;
        }
        reader.close();
        isr.close();
        in.close();
    }
}

 

728x90
반응형
Contents

📝 포스팅 주소를 복사했습니다 📝

이 글이 도움이 되었다면 공감 부탁드립니다👍