This week's book giveaway is in the Open Source forum.
We're giving away four copies of Programmers Guide to Apache Thrift and have Randy Abernethy on-line!
See this thread for details.
Win a copy of Programmers Guide to Apache Thrift this week in the Open Source 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
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

Read the header of CSV file  RSS feed

 
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: 64471
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: 5475
143
Android Firefox Browser Mac OS X Safari Tomcat Server VI Editor
  • 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: 64471
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.
 
ice is for people that are not already cool. Chill with this tiny ad:
ScroogeXHTML - small and flexible RTF to HTML converter library
https://coderanch.com/t/710903/ScroogeXHTML-RTF-HTML-XHTML-converter
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!