프로그래밍/java

자바 파일 인코딩 알아내기

Super User 2010. 4. 15. 18:06



FileReader 같은 곳의 getEncoding 은 시스템의 기본 charset 밖엔 리턴하지 않는다.

 

실제 파일의 정확한 인코딩을 알아내기 위해서

 

http://glaforge.free.fr/wiki/index.php?wiki=GuessEncoding

 

위 라이브러리를 사용해봤다.

 

 public static String getFileEncoding(String fullPath) throws IOException {
  File file = new File(fullPath);
  Charset charset = CharsetToolkit.guessEncoding(file, 4096);
  
  return charset.toString();
 }

 

이런 형식으로 사용하면 된다.