Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java : How to convert java.lang.String to ISO 8859-1 format

Tags:

java

encoding

iso

In my application, i'm parsing ISO 8859-1 formatted data via CSVParser. But when i store parsed data to a String array, then cross check with corresponding ISO 8859-1 formatted data in the database, the string array not supporting some character mapping(Eg: µ is encoded as ?).This is my parsing code :

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, is used to hold parsed data.

like image 778
Master Mind Avatar asked Nov 19 '12 05:11

Master Mind


1 Answers

You need to specify CharSet while creating InputStreamReader

Example:

new InputStreamReader(new FileInputStream(new File(directory)),Charset.forName("ISO-8859-1"))
like image 68
kosa Avatar answered Sep 22 '22 21:09

kosa