- Arawn's Dev Blog
- Outsider's Dev Story
- Toby's Epril
- Benelog
- NHN 개발자 블로그
- SK 플래닛 기술 블로그
- OLC CENTER
- 소프트웨어 경영/공학 블로그
- 모바일 컨버전스
- KOSR - Korea Operating System …
- 넥스트리 블로그
- 리버스코어 ReverseCore
- SLiPP
- 개발자를 위하여... (Nextree 임병인 수석)
- "트위터 부트스트랩: 디자이너도 놀라워할 매끈하고 직관…
- Learning English - The English…
- real-english.com
- 'DataScience/Deep Learning' 카테…
- Deep Learning Summer School, M…
- Deep Learning Courses
민서네집
windows에서 java console 프로그램의 출력을 redirect 해서 UTF-8 로 파일 저장 본문
로컬에서 JBoss 서버를 돌려서 command 창에 출력되는 system output을 redirection 시켜서 파일로 저장했는데, TAIL BLAZER 라는 tail 류의 프로그램에서 한글이 제대로 안보이는 것이다.
Notepad++ 로 봐도 EUC-KR 형식이라고 표시되는데, 인코딩 메뉴에서 "UTF-8로 표시"를 해야지 한글이 제대로 보였다.
그래서 이 파일을 UTF-8 인코딩으로 생성되게끔 인터넷에서 검색을 해 보았다.
처음에는 Windows Command 창에서 코드페이지를 유니코드로 바꿔서 redirect 시켜주면 될 줄 알았는데, 배치 프로그램 안에서
chcp 65001 > nul
를 해 주거나
java 실행 파일 앞에 cmd.exe /c chcp 65001 > nul & 를 써 줘도 되지 않았다.
java에서 시스템 인코딩을 바꿔서 인식시켜 주려고, java를 실행시킬 때 명령줄에 -Dfile.encoding=UTF-8 라는 옵션을 추가했다.
그랬더니 UTF-8로 출력이 되었다.
결국은 배치 프로그램 안에서 코드 페이지를 바꾸는 것은 아무 효과도 보지 못했고, 결론은 java를 실행시킬 때, -Dfile.encoding=UTF-8 라는 옵션을 줘야 한다.
file.encoding은 대소문자를 주의해야 함. 전부 소문자로 쓰지 않으면 인식하지 않음.
참고로, 다음은 구글링해서 찾은 웹페이지들이다.
Windows 운영체제에서 java console 프로그램의 output을 redirect해서 file로 저장 시 UTF-8 로 저장.
https://stackoverflow.com/questions/16598785/save-text-file-in-utf-8-encoding-using-cmd-exe
https://stackoverflow.com/questions/11962172/echo-utf-8-characters-in-windows-batch/12000085
https://superuser.com/questions/237081/whats-the-code-page-of-utf-8#272184
https://stackoverflow.com/questions/28567208/how-can-i-change-the-standard-out-to-utf-8-in-java
https://stackoverflow.com/questions/361975/setting-the-default-java-character-encoding
참고로, 배치 프로그램 안에서 chcp 65001 로 코드 페이지를 바꿔주면 속성에서 글꼴을 True Type 폰트로 바꿔줘야지 다음에 다시 실행할 때부터 글자가 보인다.
'Java' 카테고리의 다른 글
JBoss7 standalone.xml 암호화된 password 생성 (0) | 2018.09.22 |
---|---|
Java Decompiler (0) | 2018.02.06 |
Eclipse + JEUS 연동하기 (0) | 2017.11.29 |
[오류해결] svn cleanup failed-previous operation has not finished; run cleanup if it was interrupted (0) | 2017.11.29 |
[Eclipse] Failed to load JavaHL Library (Subversion Native Library Not Available) (0) | 2017.11.29 |