• 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

Creating a CSV file

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

I want to create a csv file , I have to give heading and beside it there will be detail of that heading. such as Name is an heading and bellow it name of students will be. So, what can i do.

Thank's
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Writing CSV files is very easy. "CSV" means "comma separated values". A CSV file consist of records; each line is a record, and the fields in each record are separated by commas.

You just write a program that opens the file for writing, first write the header line, then loop through the records, for each record write a line with the data for that record (fields separated by spaces), then close the file.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
CSV does not have a concept of headers. It has rows and columns of values. ANy program processing a CSV file is of course free to treat certain rows or cells in special ways (as if they were headers).

It gets a little more complicated that Jesper described, though. Sometimes the delimiter is not a comma but a semicolon, and if the delimiter occurs inside of a cell, then the cell contents need to be enclosed in double quotes. And if the contents contain double quotes or newline characters, then those need to be escaped.

Before you've coded up all these special cases, you might as well use a ready-made library for reading and writing CSVs. The AccessingFileFormats FAQ page lists several such libraries.
 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
try this

http://ostermiller.org/utils/CSV.html

it has the utility programs you can extract to suit your needs
 
reply
    Bookmark Topic Watch Topic
  • New Topic