Results 1 to 2 of 2
  1. #1
    csrLewis93 is offline Member
    Join Date
    Feb 2013
    Rep Power

    Default 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:
    Java Code:
    import java.util.Scanner;
    public class filecount
    	public static void main(String[] args) throws FileNotFoundException
    		Scanner input = new Scanner(;
    		System.out.print("Input file name ");
    		String inputFileName =;
    Any help would be appreciated.

  2. #2
    wsaryada is offline Senior Member
    Join Date
    Jun 2007
    Bali, Indonesia
    Rep Power

    Default 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)

Similar Threads

  1. Number of words in file. Help.
    By itskeith in forum New To Java
    Replies: 1
    Last Post: 12-02-2012, 11:14 PM
  2. Replies: 8
    Last Post: 01-21-2012, 01:14 AM
  3. Two '\n' characters between lines while reading File
    By subith86 in forum New To Java
    Replies: 6
    Last Post: 02-26-2011, 09:56 AM
  4. Finding words (and more) in another file
    By Lund01 in forum Java Applets
    Replies: 5
    Last Post: 09-30-2010, 01:03 PM
  5. Replies: 2
    Last Post: 12-10-2009, 12:06 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts