troubleshooting Question

reading strings

Avatar of javanewbie
javanewbie asked on
16 Comments1 Solution266 ViewsLast Modified:
hi, im writing a program that has to ouput all the words in a text file seperately. so for example if in the text file there was a line with the words "today is monday" then the output would be:

the code i have so far is as follows:


public class IODemoClass
     public static void main (String[] args) throws IOException, ClassNotFoundException
          // For J++: to keep the application window open
          BufferedReader br = new BufferedReader(new InputStreamReader(;

          String wait = br.readLine();
     } // end main()

     public static void testString(String fileName) throws IOException, FileNotFoundException {

          // now open the file and create a buffer object that can
          // be used to read the text from the stream
          FileReader fr = new FileReader(fileName);
          BufferedReader fbr = new BufferedReader(fr);

          String current = null;
          int total = 0;
          while (fbr.ready()) {  // while there is more text to read from fr
               current = fbr.readLine();  // read the next line from the file
          fbr.close(); // closes the buffered reader and the connected file.
          System.out.println(total + " lines read from file " + fileName);
     } // end testInt()

} // end class

what this dies is opens the file and output the number of lines in the file. can anyone help me so that the program now outputs all the words within the file?
Join our community to see this answer!
Unlock 1 Answer and 16 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 16 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros