Java BufferedReader behavior in CSV vs TXT file
Posted
by
Gabriel
on Stack Overflow
See other posts from Stack Overflow
or by Gabriel
Published on 2011-01-03T14:08:36Z
Indexed on
2011/01/03
15:53 UTC
Read the original article
Hit count: 208
If i try to read a CSV file called csv_file.csv
. The problem is that when i read lines with BufferedReader.readLine()
it skips the first line with months. But when i rename the file to csv_file.txt
it reads it allright and it's not skipping the first line.
Is there an undocumented "feature" of BufferedReader that i'm not aware?
Example of file:
Months, SEP2010, OCT2010, NOV2010
col1, col2, col3, col4, col5
aaa,,sdf,"12,456",bla bla bla, xsaffadfafda
and so on, and so on, "10,00", xxx, xxx
The code:
FileInputStream stream = new FileInputStream(UploadSupport.TEMPORARY_FILES_PATH+fileName);
BufferedReader br = new BufferedReader(new InputStreamReader(stream, "UTF-8"));
String line = br.readLine();
String months[] = line.split(",");
while ((line=br.readLine())!=null) {
/*parse other lines*/
}
© Stack Overflow or respective owner