Win a copy of 97 Things Every Java Programmer Should Know this week in the Java in General forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

Read the header of CSV file

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

I implemented a program which stores all the lines of an CSV file in a hashlist. But it is beginning at the first row of the csv file. I use the Bufferreader to read the lines and store them in a array list . But how can I also take the headers of the csv file? Should I implement that in the buffer reader as well? And how?

Thank you all.
 
Marshal
Posts: 69447
277
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would start by looking at different ways to read files. They are often better than trying to write your own CSV reading program.
You can of course simply miss out the first line. Or read one line.If you change skip(...) to limit(...) in line 7, you can get only the header.
 
Saloon Keeper
Posts: 6448
158
Android Mac OS X Firefox Browser VI Editor Tomcat Server Safari
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
CSV files have no concept of a header. If the first line contains row names (which I assume is what you're talking about), what is the difficulty in treating it as such when reading all the lines?

If you're using a CSV library (which I recommend), that would probably have an option to treat the first row as a header.
 
Lia Tas
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes I want to output all the rows from the file and the headers. But now just the rows are printed without header

while(line=be.readline() !=null)...
 
Campbell Ritchie
Marshal
Posts: 69447
277
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Lia Tas wrote:. . . while(line=be.readline() !=null)...

That will get you all the lines. You want one line, or alll but one.
 
I do some of my very best work in water. Like this tiny ad:
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic