2

I'm trying to read a CSV file with the following characters: â/ô/etc. My code isn't parsing these characters well. I'm getting the � character/symbol instead of the real character.

This is the code I'm using for reading the CSV file:

 private List<String[]> getRows(File f) throws IOException {
    //FileReader fileReader = new FileReader(f);
    InputStreamReader inputStreamReader = new InputStreamReader(new FileInputStream(f), "UTF-8");

    try {
        CSVReader reader = new CSVReader(inputStreamReader, ';');

        try {
            return reader.readAll();
        } finally {
            reader.close();
        }
    } finally {
        inputStreamReader.close();
    }
}

Who can help me? Thanks!

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
Danny Gloudemans
  • 2,597
  • 7
  • 39
  • 57
  • Where are you getting the incorrect characters. Presumably when you print them somehwere? Show us _that_ code. If the file is indeed UTF-8 encoded what you have shown will work. – Boris the Spider Mar 17 '14 at 15:25
  • This link below will help your problem http://stackoverflow.com/a/23912646/2154012 – gurtell May 28 '14 at 13:17

1 Answers1

-4

Try something like below.

  File file = new File("H:\\file name.csv");


  BufferedReader br = new BufferedReader(new FileReader(file));
  int lineNumber = 0; 

  while ((line = br.readLine()) != null) {

    lineNumber++;


    if ( line.trim().length() == 0 ) {  
        continue;  
      }

    arr=line.split(",");

   for (int j=0;j<arr.length;j++)
    {
     ft=arr[j];
     ft=ft.trim();

   System.out.print(ft);     

    }
  }
Kerri Williams
  • 39
  • 1
  • 1
  • 6