메모리 스트림
public static void main(String[] args) throws IOException {
byte[] input = {1, 2, 3};
// 메모리에 쓰기
ByteArrayOutputStream baos = new ByteArrayOutputStream();
baos.write(input);
// 메모리에서 읽기
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
byte[] bytes = bais.readAllBytes();
System.out.println(Arrays.toString(bytes));
}
문자 스트림
public static void main(String[] args) throws IOException {
PrintStream printStream = System.out;
byte[] bytes = "Hello!\n".getBytes(UTF_8);
printStream.write(bytes);
printStream.println("Print!");
}
'개발이 좋아서 > Java가 좋아서' 카테고리의 다른 글
I/O 기본2 - 문자 다루기 (BufferedReader) (0) | 2024.11.26 |
---|---|
I/O 기본1 - 파일 입출력과 성능 최적화 (buffered) (0) | 2024.11.26 |
I/O 기본1 - 스트림 (0) | 2024.11.26 |
문자 인코딩 (0) | 2024.11.26 |
Exception (0) | 2023.05.09 |