Search code examples
javasystem.out

Java read text file extrange line


I am trying to process a csv file in java, but when print the result, the text have too many spaces.

enter image description here

With this code print like the img above:

FileInputStream fstream = new FileInputStream("prueba.csv");
// or using Scaner
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String strLine;
//Read File Line By Line
while ((strLine = br.readLine()) != null)   {
  System.out.println(strLine);
} 

}

If open the file in for example notapad++ or windows notepad it looks well. I tried to remove spaces but it too was not success :( What can I do?


Solution

  • This will work for you as per the https://stackoverflow.com/a/14411707/4848659. Change bufferedReader initialization as follows,

    BufferedReader br = new BufferedReader(new InputStreamReader(fstream, "UTF16"));