...
maven 설정
Code Block language xml <dependency> <groupId>com.ibm.icu</groupId> <artifactId>icu4j</artifactId> <version>52.1</version> </dependency>
CharsetDetector 클래스로 인코딩 확인
Code Block language java package com.ktnet.tradesign; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import org.apache.commons.io.IOUtils; import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.ibm.icu.text.CharsetDetector; import com.ibm.icu.text.CharsetMatch; public class CharDetector { private String[] data = { "ms949.txt", "utf8.txt" }; Logger logger = LoggerFactory.getLogger(CharDetector.class); @Test public void detect() throws IOException { CharsetDetector detector; CharsetMatch match; FileInputStream fis = null; try { for(String fn : data) { File f = new File(fn); fis = new FileInputStream(f); byte[] byteData = new byte[(int) f.length()]; fis.read(byteData); fis.close(); detector = new CharsetDetector(); detector.setText(byteData); match = detector.detect(); logger.info(fn + " encoding is \"" + match.getName() + "\""); } } finally { IOUtils.closeQuietly(fis); } } }
...