How to ignore first line of .txt when using Scanner class

前端 未结 3 801
太阳男子
太阳男子 2021-01-07 00:05

I have a text file that reads:

Description|SKU|Retail Price|Discount
Tassimo T46 Home Brewing System|43-0439-6|17999|0.30
Moto Precise Fit Rear Wiper Blade|0         


        
相关标签:
3条回答
  • 2021-01-07 00:10

    how about calling scanner.nextLine() as outside your loop.

    scanner.nextLine();//this would read the first line from the text file
     while (scanner.hasNext()) {
                String row = scanner.nextLine();
    
    0 讨论(0)
  • 2021-01-07 00:12

    Simply calling scanner.nextLine() once before any processing should do the trick.

    0 讨论(0)
  • 2021-01-07 00:18
    scanner.nextLine();
    while (scanner.hasNext()) {
          String row = scanner.nextLine();
          ....
    
    0 讨论(0)
提交回复
热议问题