inblog logo
|
khh
    java

    보조스트림

    Jan 08, 2024
    보조스트림
     
    notion image
     
    package ex15; import java.io.IOException; import java.io.InputStream; public class StreamEx01 { public static void main(String[] args) { InputStream input = System.in; // 키보드 try { int value = input.read(); // 아스키 코드 System.out.println("받은 값 : " + value); } catch (IOException e) { throw new RuntimeException(e); } } }
    notion image
     
    notion image
     
    보조스트림 (버퍼)
    1) read
    2) write
     
    💡
    끝에는 꼭 \n을 적기
    package ex15; import java.io.BufferedWriter; import java.io.IOException; import java.io.OutputStreamWriter; public class StreamEx04 { public static void main(String[] args) { BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); // 모니터 try { bw.write("안녕\n"); // 내려쓰기 bw.write("반가워\n"); // 엔터기능 readLine이 \n을 읽기 때문에 \n을 적어줘야 읽는다. bw.flush(); // 플러쉬를 해야 나옴 } catch (IOException e) { throw new RuntimeException(e); } } }
     
     
    Share article

    khh

    RSS·Powered by Inblog