We help IT Professionals succeed at work.

Reading file skip header

AndyC1000
AndyC1000 asked
on
Dear all,

I want to skip the first line (header) when reading a file.  I've placed checks in previous code,  if value of the cell matches the string ignore, however in this case there are too many columns.

See below code block.

Thanks

File f = new File(filename);
Scanner sc = new Scanner(f);

while (sc.hasNextLine()) {
  String line = sc.nextLine();
  String[] details = line.split(",");
}

Open in new window

Comment
Watch Question

IT Business Systems Analyst / Software Developer
Top Expert 2015
Commented:
Try the below...

File f = new File(filename);
Scanner sc = new Scanner(f);

if (sc.hasNextLine()) {
  sc.nextLine();
}

while (sc.hasNextLine()) {
  String line = sc.nextLine();
  String[] details = line.split(",");
}