By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,468 Members | 1,865 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,468 IT Pros & Developers. It's quick & easy.

Building a file reading app

P: 4
Hi, I have been given the task to make a file reading program which will:

Take in a text file
Read it and display its contents
Do a quick word count
Do a vowel count

Im kind of new to java programming so any help will be appreciated. Either by code or ideas on how the code should be laid out.

Thanks

Arch
Nov 30 '06 #1
Share this Question
Share on Google+
3 Replies


10K+
P: 13,264
Hi, I have been given the task to make a file reading program which will:

Take in a text file
Read it and display its contents
Do a quick word count
Do a vowel count

Im kind of new to java programming so any help will be appreciated. Either by code or ideas on how the code should be laid out.

Thanks

Arch
Start by getting the file and showing the ontents to the screen. You will need to use a combination of FileReader and BufferedReader classes for reading the file. Look them up and write some code then post it and we'll see if you need more help.
Nov 30 '06 #2

10K+
P: 13,264
Start by getting the file and showing the ontents to the screen. You will need to use a combination of FileReader and BufferedReader classes for reading the file. Look them up and write some code then post it and we'll see if you need more help.
If you are cleverly lazy you could just look at this

http://www.thescripts.com/forum/thread571143.html
Nov 30 '06 #3

P: 4
I have found some code which i think will read the text file. This was found on a website i think i might be able to modify this and use it in my code.

Expand|Select|Wrap|Line Numbers
  1. import java.io.*;
  2.  
  3. public class ReadFile{
  4.     public static void main(String[] args){
  5.         try {
  6.  
  7.             /*    Sets up a file reader to read the file passed on the command
  8.                 line one character at a time */
  9.             FileReader input = new FileReader(args[0]);
  10.  
  11.             /* Filter FileReader through a Buffered read to read a line at a
  12.                time */
  13.             BufferedReader bufRead = new BufferedReader(input);
  14.  
  15.             String line;     // String that holds current file line
  16.             int count = 0;    // Line number of count 
  17.  
  18.             // Read first line
  19.             line = bufRead.readLine();
  20.             count++;
  21.  
  22.             // Read through file one line at time. Print line # and line
  23.             while (line != null){
  24.                 System.out.println(count+": "+line);
  25.                 line = bufRead.readLine();
  26.                 count++;
  27.             }
  28.  
  29.             bufRead.close();
  30.  
  31.  
  32.  
  33.         }catch (IOException c){
  34.             // If another exception is generated, print a stack trace
  35.             c.printStackTrace();
  36.         }
  37.  
  38.     }// end main
  39. }
It will allow me to read a text file and it will display the results on screen :D

I have also bought a book which should hopefully help.

i might be posting back on here later though.

Thanks

Arch
Nov 30 '06 #4

Post your reply

Sign in to post your reply or Sign up for a free account.