• Post Reply Bookmark Topic Watch Topic
  • New Topic

Parsing a CSV file

 
Adi Kulkarni
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ,

I need to parse a CSV file which might have a data in the following format.

"a" , "b" , "c" , "d" , "e"

This line would comprise one record. I want to parse each such line such that I capture each element in a local java variable eg

String a = a
String b = b
String c = c

Finally I would be running a loop for each such line and using the variables to run my logic.

Currently I would be working on small data file, but eventually this CSV file can grow very very big.

Can anyone suggest me a method to parse such a CSV file ?

Thanks,
Aditya
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The http://faq.javaranch.com/java/AccessingFileFormats page links to several libraries for reading and writing CSV files. CSV isn't quite as simple as it looks at first, so I'd recommend to use one of those.
 
Adi Kulkarni
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Ulf,

I 'm planning to use opencsv APIs .

I have downloaded CSVObjects-bin-0.5b and csvbeans-0.7.1 and added the main jars in the build path

What else do I need to download/add? What java packages need to be imported ?

Thanks,
Aditya
 
Adi Kulkarni
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

Following is the document to configure the setup.

http://sourceforge.net/docman/display_doc.php?docid=29315&group_id=143837

Doing this i'm not able to resolve the class CSVReader since the import au.com.bytecode.opencsv is also not getting resolved.

I havent downloaded the ANT and XDoclet tool mentioned in the document. Do I need to install that too ?

Please advice

Thanks,
Aditya
 
Rob Spoor
Sheriff
Posts: 20820
68
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Adi Kulkarni wrote:Doing this i'm not able to resolve the class CSVReader since the import au.com.bytecode.opencsv is also not getting resolved.

That's because that class is defined in opencsv, also on the link provided by Ulf. Download that one as well.
 
Adi Kulkarni
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Rob,

Do you mean that I need to download the opencsv source along with the opencsv binary object ?

Also is the ANT tool and XDoclet required? I 'm not aware of both these tools ?

Thanks again,
Aditya
SCJP 1.5
 
Rob Spoor
Sheriff
Posts: 20820
68
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Adi Kulkarni wrote:Do you mean that I need to download the opencsv source along with the opencsv binary object ?

No, you only need the opencsv binary. But you hadn't said you downloaded that one.

Have you also checked your classpath?

Also is the ANT tool and XDoclet required?

No. ANT makes it easier for you to build, but it's not required.
 
Adi Kulkarni
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Rob,

I tried adding the jars in the classpath variable defined in the windows environment variables.

example: If a.jar and b.jar then

I added the path for them in classpath variable. Am I making any mistake in setting the classpath?

Also , I am using eclipse. Where in eclipse can I set/check the classpath ?

Note : I have downloaded the CSVObjects binary file.

Thanks,
Aditya
 
Adi Kulkarni
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can anyone help me with this basic issue
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!