This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
Hi, my requirement is to read from a .csv (comma seprated version) file. Presently what i am doing is i am reading each line and creating stringtokenizer with comma(,)and reading one by one element.Is this approach is correct or is there any other procedure to read .csv files in java.Thanks in advance
The trouble with CSV is that there are different flavours. You need to find out the exact spec of the CSV you're trying to import. For example, some formats allow commas or line-breaks within items. Usually this is done by wrapping the item in single- or double-quotes (e.g. "bloggs, f"). If you simply look at commas you'll end up breaking this item into two pieces when it should be considered as one. Note: there are also different conventions about how to escape quotes within an item. Once you know which flavour of CSV you're after, search Google. Other people will definitely have solved the problem already. Don't reinvent the wheel.
Joined: Jan 03, 2003
Hi, my file will contain ,(comma) only .Other than that no special characters are allowed.but my problem is sometimes i will get blank values in between.but StringTokenizer is ignoring blank.Presently we are using jdk1.3 so that i can't use string.split(",").If any one knows the solution please let me know. Thanks in advance
Hi, Solution depends on what kind of file do you want to upload. In case what u want to upload is an excel, you can use jakarta's POI. However, in case what you have is an .csv , you can use a utility called SQL Loader. Enjoy...
~ Pratibha Malhotra<br /> <br />Sun Certified Java Programmer<br />SCEA 1.4 (In Progress)<br />~~~~~~~~~~~~~~~~~~~~~~~~~~~<br />"Many of life's failures are people who did not realize how close they were to success when they gave up!!"