1

I have spanish data in my oracle database (charectorset AL32UTF8). I am reading the data from the db and writing into a csv file, and from csv I am reading the data again and doing some operation. But in the csv file it is displaying junk values.

I did the same thing on linux and it is working correctly.

public class T {

    CSVWriter out = null;

    private void write(String[] values) throws IOException {
        out.writeNext(values);
    }

    public static void main(String[] args) throws IOException {

        File f  = new File("s.csv");

        FileOutputStream os = new FileOutputStream(f, false);

        CSVWriter out = new CSVWriter(
            new BufferedWriter(
                new OutputStreamWriter(
                    os, "UTF-8")));
    }
}
ramya
  • 43
  • 1
  • 6

1 Answers1

0

you have to tell Excel to use the correct encoding when opening the CSV file

see below:

Is it possible to force Excel recognize UTF-8 CSV files automatically?

Jose Zevallos
  • 655
  • 4
  • 3
  • I dont want to do it manually, java should read the excel correctly. – ramya Jun 12 '17 at 11:24
  • From the code, I see that you are correctly using UTF-8 when creating the csv file. Then it is only missing to use "UTF-8" when opening/reading the CSV file in Java. BufferedReader in = new BufferedReader( new InputStreamReader( new FileInputStream("your CSV file goes here"), "UTF8")); – Jose Zevallos Jun 12 '17 at 11:31