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!
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);
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.