Java Scanner Usage countFileLines(Scanner fin)

Here you can find the source of countFileLines(Scanner fin)

Description

Counts the number of lines that are in an input file.

License

Apache License

Parameter

Parameter Description
fin a parameter

Return

the number of lines in the file

Declaration

public static int countFileLines(Scanner fin) 

Method Source Code

//package com.java2s;
/*/*from www  .ja  v  a  2 s .  com*/
*@author Grant Callant
*My FileUtil Class to open and read
*as well as open and write files, user specified, and
*string literal file names.
*  * Copyright 2015 Grant Callant
    
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
    
http://www.apache.org/licenses/LICENSE-2.0
    
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

import java.util.Scanner;

public class Main {
    /**
     * Counts the number of lines that are in an input file.
     * @param fin
     * @return the number of lines in the file
     */
    public static int countFileLines(Scanner fin) {
        int count = 0;
        while (fin.hasNext()) {
            count++;
            fin.nextLine();
        }
        return count;
    }
}

Related

  1. common(Scanner in)
  2. computeSumTable(Scanner in, short n)
  3. confirm(String message)
  4. confirm(String message)
  5. confirmAction(String warning)
  6. createKeyboardScanner()
  7. createScannerForString(String s)
  8. enterToContinue()
  9. equalsToIgnoreEndline(String expected, String actual)