aspose file tools
The moose likes Java in General and the fly likes How to extract CSV data and bind to bean? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "How to extract CSV data and bind to bean?" Watch "How to extract CSV data and bind to bean?" New topic
Author

How to extract CSV data and bind to bean?

James Dekker
Ranch Hand

Joined: Dec 09, 2006
Posts: 215
Suppose, you have text file which contains the following data delimited by commas:



And you have constructed a POJO (bean) which looks like this:



How can one go about loading this file into memory, extracting out the commas, and assigning the data to the correct properties inside LineItem?

Should it be done inside a Helper class that does both (File I/O and strips out the commas and then binds to the LineItem class)?

Or should it also include a 3rd class which binds to to an ArrayList<LineItem> lineItems which would set them to the appropriate properties?

Thanks,
Remko Strating
Ranch Hand

Joined: Dec 28, 2006
Posts: 893
I would use the java.util.Scanner class.

The following link explains the working of the scanner class and gives you an example

Scanning text with java.util.Scanner


Remko (My website)
SCJP 1.5, SCWCD 1.4, SCDJWS 1.4, SCBCD 1.5, ITIL(Manager), Prince2(Practitioner), Reading/ gaining experience for SCEA,
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to extract CSV data and bind to bean?
 
Similar Threads
FBN: MVC pattern without Model Class
? How to call JAXP/JDOM from other class
Sorting using Comparable interface
Bean Initialization fails... Why?
Domain class design question