View Single Post
Old Nov 11th, 2004, 4:03 PM   #2
Mjordan2nd
The Supreme Ruler
 
Join Date: May 2004
Location: Houston
Posts: 1,476
Rep Power: 6 Mjordan2nd is on a distinguished road
I made a few small changes to your program. I changed it first to a do-while loop, because it has to go through at least once. I also put your readline inside the loop. Then, your sort method was giving me some errors, so I used a sort method inside the collectinos class. Just changed three lines, basically. Here's your edited code.

import java.util.*;
import java.io.*;
public class Example2
{
  public static void main() throws IOException
  {
    //set up input stream
    BufferedReader filein = new BufferedReader(new FileReader("filein.txt"));
 //set up output stream
  PrintWriter fileout = new PrintWriter(new FileWriter("fileout.txt"));

   
    //Declare variables
    String nextLine; //a line read from file
    StringTokenizer t; //the words within the line
    ArrayList a = new ArrayList(); //store all words here
    String s; //next word
    boolean isAWord; //true if string represents a Word    
    char[] nVal = { '.',',','!',':',';','?' }; // not valid characters
    int countGood=0, countBad=0; 
    
    System.out.println("Starting to read");
    
    //start        
    do
    {
  nextLine = filein.readLine();   //read from input file    
      t = new StringTokenizer(nextLine); //identify words
      nextLine = nextLine.toLowerCase( );//Converts to Lowercase()
          
      while (t.hasMoreTokens())
      {   
        a.add(t.nextToken()); //add next word to list                                       
      }       
    
    Collections.sort(a);
    // This line wont work and brings up the error that it cannot resolve symbol
    
    }while (nextLine != null); //finished reading file
    
    fileout.println(a);
    
    System.out.println("Finished");
    fileout.close();
   
  }
}
__________________
"Every gun that is made, every warship launched, every rocket signifies, in the final sense, a theft from those who hunger and are not fed, from those who are cold and are not clothed. The world in arms is not spending money alone. It is spending the sweat of its laborers, the genius of its scientists, the hopes of its children." - Dwight D. Eisenhower
Mjordan2nd is offline   Reply With Quote