String str = 'RTF 값';
byte[] bytes = null;
bytes = str.getBytes();
InputStream is = new ByteArrayInputStream(bytes);
try {
byte[] bytes = null;
bytes = str.getBytes();
InputStream is = new ByteArrayInputStream(bytes);
try {
// rtf 파일의 경우
// FileInputStream is = new FileInputStream("a.rtf");
RTFEditorKit kit = new RTFEditorKit();
Document doc = kit.createDefaultDocument();
kit.read(is, doc, 0);
String plainText = doc.getText(0, doc.getLength());
System.out.println("text:" + new String(plainText.getBytes("8859_1"),"KSC5601"));
} catch (Exception e) {
// TODO: handle exception
}
참고: DB에서의 한글 charset 변환
// TODO: handle exception
}
참고: DB에서의 한글 charset 변환
DB 입출력 기능을 하는 부분을 다음과 같은 형식으로 수정해 주면 됩니다.
ISO8859 인 DB에 한글을 넣을 땐 다음과 같은 코드를 사용합니다.
String str = "한글";
String result = new String(str.getBytes("KSC5601"),"8859_1") ;
DB에서 받아올 땐 앞 뒤의 charset을 표현하는 문자열의 위치를 바꾸면 됩니다.
String str = rs.getString();
String result = new String(str.getBytes("8859_1"),"KSC5601") ;