File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to write into specific fields in CSV file using IO?

 
Akhilesh Murthy
Greenhorn
Posts: 24
Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I want to write into a CSV file, into specific fields of the file.
Can i write the specific fields in file using IO?

Thanks,
Akhilesh
 
John Jai
Rancher
Posts: 1776
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check for CSV in AccessingFileFormats page.
 
Akhilesh Murthy
Greenhorn
Posts: 24
Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi The file formats had more of parsers and reader API's. My requirement was mainly for writing into specific fields of the file.

Thanks
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Akhilesh Murthy wrote:Hi The file formats had more of parsers and reader API's. My requirement was mainly for writing into specific fields of the file.

Thanks


You can't write directly into a single field of a CSV file. You have to read the file into memory, change what you want to change, and write it back out. Note that you can operate on one line at a time--you don't necessarily have to have the entire file in memory.
 
Akhilesh Murthy
Greenhorn
Posts: 24
Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As a .csv file is stored in form of an excel the fields are populated based on the date written. Now my question is how can i write into a specific cell of the file. i.e, specific cell of the excel file.

Thanks Akhilesh
 
Campbell Ritchie
Sheriff
Pie
Posts: 47293
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving thread as too difficult a question for “beginning”
Don’t know, but investigate something called POI from the Apache foundation.
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Akhilesh Murthy wrote:As a .csv file is stored in form of an excel


No, a CSV file is a "comma-separated-value" file. That is, a plain text file that uses commas (or some other delimiter) do separate one field from another.

the fields are populated based on the date written. Now my question is how can i write into a specific cell of the file. i.e, specific cell of the excel file.


As I said: Read the file, find the appropriate place, change what you need to change, write the object model back out to the file.

This is the only way to do it; you can't just modify some part of the file directly, unless you a) know ahead of time the exact byte position of where you want to make the change AND b) the change you make will not use any more bytes than were already allocated for that field in that file. (And if it meets those conditions, then it's not really a CSV file.)

Now, there may be libraries out there--such as POI or a CSV manipulation library--that will abstract away the details of finding the cell and re-writing the entire file, so that you can just do something like setValue(row, column, value). If that's what you're looking for, see the link in the first reply.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic