2012-11-19 16 views
7

在我的應用程序中,我通過CSVParser解析ISO 8859-1格式的數據。但是當我將分析後的數據存儲到字符串數組中時,然後與數據庫中相應的ISO 8859-1格式化數據交叉檢查,字符串數組不支持某些字符映射(例如:μ被編碼爲?)。這是我的解析代碼:Java:如何將java.lang.String轉換爲ISO 8859-1格式

CSVReader reader; 
    List<String[]> list = new ArrayList<String[]>(); 
    try { 
     reader = new CSVReader(new InputStreamReader(new FileInputStream(new File(directory))), Configuration.CSV_SEPERATOR); 

     list = reader.readAll();  
for (String[] singleStock : list) { 
} 

String [] singleStock,用於保存解析的數據。

回答

4

你需要指定CharSet同時創造InputStreamReader

例子:

new InputStreamReader(new FileInputStream(new File(directory)),Charset.forName("ISO-8859-1")) 
3

嘗試使用另一個構造爲InputStreamReader

InputStreamReader(InputStream in, String charsetName) 
Create an InputStreamReader that uses the named charset. 
4

使用InputStreamReader將需要知道流是ISO 8859 -1格式。嘗試將此參數添加到InputStreamReader中...

new InputStreamReader(... , Charset.forName("ISO-8859-1")) 
相關問題