• Post Reply Bookmark Topic Watch Topic
  • New Topic

Read a Comma Delimited CSV File

 
Elle Atechsy
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I'm trying to read a comma delimited CSV file. On my desktop, Win XP, it works, but on Linux it does not work. I believe I need to set/change the character set. But not sure if I really need to do that, or how to do it.

Please take a look at my code below, and provide some suggestions.

Thanks!


 
Prabhu Venkatachalam
Ranch Hand
Posts: 502
Java jQuery Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Java file seems to be OK. can you post error you are getting in Linux? or is it not reading the file properly?
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
it does not work.

What does this mean? Are there any exceptions? TellTheDetails
 
Peter Chase
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As previous posters have said, the code looks as if it ought basically to work. Perhaps, if you are mixing and matching files from various O.S., you could be tripping over line-ending problems.

You suggest that you could have a "character set" problem. It would be unusual to have such problems, if your file only contains ordinary ASCII English characters, but you could have problems if it contains international characters in some encoding. To switch encoding, you could read the file with a FileInputStream, then use an InputStreamReader to read it; the InputStreamReader allows encoding to be specified.

The code has a number of general issues, too. It should use try..finally, to ensure the Reader is always closed. The ArrayList is populated but never used. The same strings are trimmed multiple times. Etc.
 
Elle Atechsy
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you all for your responses.

I wasn't getting any errors. The file was just not being read properly, and therefore wasn't returning any results.

Peter,

Thank you for catching my discrepancies. Also, for the suggestion to use the FileInputStream & the InputStreamReader. It worked like a charm!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!