![notion image](https://www.notion.so/image/https%3A%2F%2Fprod-files-secure.s3.us-west-2.amazonaws.com%2F190e681e-8a6a-4223-a5b4-4d781100c280%2Fd04ec146-68cc-4bed-bbec-452e1f18483d%2FKakaoTalk_20240108_114359356.jpg?table=block&id=0b9d4349-22d3-4455-be17-0f6eec830653&cache=v2)
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](https://www.notion.so/image/https%3A%2F%2Fprod-files-secure.s3.us-west-2.amazonaws.com%2F190e681e-8a6a-4223-a5b4-4d781100c280%2F82cdd1e4-6a22-4c09-a14a-7b60c653fdfd%2FScreenshot_1.png?table=block&id=1deca594-1b16-4f86-8bc6-5d2062b77e9a&cache=v2)
![notion image](https://www.notion.so/image/https%3A%2F%2Fprod-files-secure.s3.us-west-2.amazonaws.com%2F190e681e-8a6a-4223-a5b4-4d781100c280%2F7aaacb9c-8e02-474d-ac2b-c3e88f74ab9b%2FKakaoTalk_20240108_114724403.jpg?table=block&id=beb172a3-85c7-4c71-bbb5-fd4e1e0cf516&cache=v2)
보조스트림 (버퍼)
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