Results 1 to 2 of 2
- 02-25-2013, 02:12 AM #1
Member
- Join Date
- Feb 2013
- Posts
- 6
- Rep Power
- 0
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.Java Code:import java.util.Scanner; import java.io.File; import java.io.FileNotFoundException; 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();
- 02-25-2013, 04:41 AM #2
Senior Member
- Join Date
- Jun 2007
- Location
- Bali, Indonesia
- Posts
- 696
- Rep Power
- 6
Re: Finding number of lines, words, and characters in a file
Hi,
- 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)Website: Learn Java by Examples
Similar Threads
-
Number of words in file. Help.
By itskeith in forum New To JavaReplies: 1Last Post: 12-02-2012, 11:14 PM -
Easy Question! Print out file, count number of lines, number of spaces w/ Scanner
By LogicalOutlier in forum New To JavaReplies: 8Last Post: 01-21-2012, 01:14 AM -
Two '\n' characters between lines while reading File
By subith86 in forum New To JavaReplies: 6Last Post: 02-26-2011, 09:56 AM -
Finding words (and more) in another file
By Lund01 in forum Java AppletsReplies: 5Last Post: 09-30-2010, 01:03 PM -
Issue With Finding Total Number of Blank Spaces in File
By Cod in forum New To JavaReplies: 2Last Post: 12-10-2009, 12:06 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks