7

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.

Master Mind
  • 2,386
  • 3
  • 31
  • 48

3 Answers3

4

You need to specify CharSet while creating InputStreamReader

Example:

new InputStreamReader(new FileInputStream(new File(directory)),Charset.forName("ISO-8859-1"))
kosa
  • 65,990
  • 13
  • 130
  • 167
4

The InputStreamReader will need to know the stream is ISO 8859-1 format. Try adding this parameter to the InputStreamReader...

new InputStreamReader( ... , Charset.forName("ISO-8859-1"))
slipperyseal
  • 2,728
  • 1
  • 13
  • 15
3

Try to use another constructor for InputStreamReader

InputStreamReader(InputStream in, String charsetName) 
Create an InputStreamReader that uses the named charset.
Nikolay Kuznetsov
  • 9,467
  • 12
  • 55
  • 101