So the point of the program is to input a file and have the program generate the number of lines, characters, and words. As of right not I can generate the lines and the words. However, I cannot generate them both at the same time like when I need to because each method has its own loop. For this reason, which ever action I have second (in this case the loop to generate the number of lines) does not work. I was wondering how I could fix this and I'm also seeking advice on how to find the number of characters in the document.
import java.io.File; import java.io.FileNotFoundException; import java.io.PrintWriter; import java.util.Scanner; /** 7 This program applies line numbers to a file. 8 */ public class LineNumberer { public static void main(String[] args) throws FileNotFoundException { // Prompt for the input and output file names Scanner console = new Scanner(System.in); System.out.print("Input file: "); String inputFileName = console.next(); // Construct the Scanner and PrintWriter objects for reading and writing //C:\Users\Ben\Documents\NetBeansProjects\Ben\src\LineNumberer\test.txt File inputFile = new File(inputFileName); Scanner in = new Scanner(inputFile); int wordNumber = 1; while (in.hasNext()) { String word = in.next(); System.out.println(word); wordNumber++; } System.out.println("There are " + wordNumber + "Words"); int lineNumber = 1; while (in.hasNextLine()) { String line = in.nextLine(); lineNumber++; } System.out.println("There are " + lineNumber + "Lines"); } }