Finding number of lines, words, and characters in a file
Hello. I need to prompt the user for a file name and then count the number of words, lines, and characters in that file. I'm new to java and don't know
where to begin. What I have so far is:
Any help would be appreciated.
public class filecount
public static void main(String args) throws FileNotFoundException
Scanner input = new Scanner(System.in);
System.out.print("Input file name ");
String inputFileName = input.next();
Re: Finding number of lines, words, and characters in a file
- First, you should learn the Basic I/O library in Java. Start in the following tutorial Lesson: Basic I/O (The Java™ Tutorials > Essential Classes), specifically read section on how to read files.
- Next, learn about the String class. You will find how to manipulate string to get the words or characters out of the file contents. Jump to the following section: Strings (The Java™ Tutorials > Learning the Java Language > Numbers and Strings)