supercsv 2.1.0을 사용하여 독일어 단어가있는 CSV 파일을 구문 분석합니다.supercsv getHeader의 인코딩 사용 방법
주어진 CSV 파일의 첫 번째 줄에는 헤더가 있습니다. 이 머리글에는 Ä, ä, Ü, ö 등의 일부 변형 된 모음이 있습니다. 예를 들어 : Betrag, Währung, 정보
내 나는이 같은 CSV의 헤더를 얻으려고 코딩에서 :
ICsvBeanReader inFile = new CsvBeanReader(new InputStreamReader(new FileInputStream(file), "UTF8"), CsvPreference.EXCEL_NORTH_EUROPE_PREFERENCE);
final String[] header = inFile.getHeader(true);
다음은 헤더 배열 내 문제입니다. 변형 된 모음이있는 모든 헤더는 utf8 charset을 사용하여 올바르게 인코딩되지 않습니다.
헤더를 올바르게 읽을 수있는 방법이 있습니까? 여기
는 의사의 단위 테스트입니다 :public class TestSuperCSV {
@Test
public void test() {
String path = "C:\\Umsatz.csv";
File file = new File(path);
try {
ICsvBeanReader inFile = new CsvBeanReader(new InputStreamReader(
new FileInputStream(file), "UTF-8"),
CsvPreference.EXCEL_NORTH_EUROPE_PREFERENCE);
final String[] header = inFile.getHeader(true);
System.out.println(header[9]); //getting "W?hrung" but needed "Währung" here
} catch (UnsupportedEncodingException | FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
종류의 안부 알렉스
'''UTF8 ''대신''UTF-8''을 사용 해보려고 했습니까? –
아니요, "UTF-8"로 문제가 해결되지 않습니다. –