• 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
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

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: 64690
225
  • 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: 5586
144
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: 64690
225
  • 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.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!