• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 31
1
Oracle Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Rancher
Posts: 1776
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Check for CSV in AccessingFileFormats page.
 
Akhilesh Murthy
Ranch Hand
Posts: 31
1
Oracle Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Ranch Hand
Posts: 31
1
Oracle Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Marshal
Posts: 79180
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
reply
    Bookmark Topic Watch Topic
  • New Topic