JAVA
[JAVA] Reader/InputStream(Byte)
아잠만_
2024. 9. 14. 09:49
Reader와 InputStream 차이
Reader | 문자타입(char타입) 문자를 중심으로 읽기 처리 [절차] 읽기 객체 생성 -> 읽기 작업 -> 종료 |
InputStream | byte타입 인코딩에 따라 한글이 깨져보일 수 있음 |
String str = "한글";
int len1 = str.getBytes("utf-8").length // 6
int len2 = str.getBytes("euc-kr").length // 4
// 인코딩 방식에 따라 byte길이가 달라질 수 있음
byte[] by = str.getBytes("utf-8");
String str2 = new String(by,"euc-kr"); // 깨질 수 있음
// 디코딩할 때는 반드시 인코딩한 글자로 해야함
throw와 try catch
throw | 오류를 떠넘기는 형식 |
try-catch | 오류를 스스로 처리하는 형식 웹에서 오류라고 인식을 못함 |