This is the description
For this assignment, you are to write a multi-class application that reads in and processes a text file. Here's what your application should do. At a prompt from your program, the user should supply the name of a text file. Your program should then read in the contents of this file, then write the file out backwards, to a file with the name backwards.txt. For example, if the file you read in looks like this:

hello there

Dana

old pal!

Then backwards.txt, after processing, should look like this:


old pal!

Dana

hello there





Well I got it for the most part, everything in my code works







Main
Java Code:
import java.util.Scanner;
import java.io.*;
public class WriterDriver {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws IOException {
        String fileName;
      Scanner nameReader = new Scanner(System.in);
      System.out.println("Enter a file name");
     fileName = nameReader.nextLine();
     Scanner scan = new Scanner(new FileReader(fileName));
     Writer d = new Writer(fileName);
     d.readLines();

     scan.close();
    }

}
Echo
Java Code:
 import java.util.Scanner;
  import java.io.*;

  public class Echo{
    String fileName; // external file name
    Scanner scan; // Scanner object for reading from external file

    public Echo(String f) throws IOException
    {
     fileName = f;
     scan = new Scanner(new FileReader(fileName));
   }

   public void readLines(){ // reads lines, hands each to processLine
     while(scan.hasNext()){
      processLine(scan.nextLine());
     }
     scan.close();
   }

   public void processLine(String line){ // does the real processing work
     System.out.println(line);
  }
 }

And here is where the work needs to be done
Java Code:
 import java.util.Scanner;
  import java.io.*;
import java.util.StringTokenizer;
public class Writer extends Echo {
     
    PrintWriter writer = new PrintWriter("something.txt");

    public Writer(String f) throws IOException {
      super(f);
      System.out.println(System.getProperty("user.dir"));
}


     public void readLines(){ // reads lines, hands each to processLine
    super.readLines();
    scan.close();
writer.close();
   }

    public void processLine(String line){ // does the real processing work
     StringTokenizer st = new StringTokenizer(line);
     while (st.hasMoreTokens()) {
     //String[] result = fileName.split("\\s");
     
  
         writer.print(st.nextToken());
         writer.print(" ");
         
         
        
     }
writer.println("");
 
  }




}
So I tried change that to
Java Code:
 import java.util.Scanner;
  import java.io.*;
import java.util.StringTokenizer;
public class Writer extends Echo {
     
    PrintWriter writer = new PrintWriter("something.txt");

    public Writer(String f) throws IOException {
      super(f);
      System.out.println(System.getProperty("user.dir"));
}


     public void readLines(){ // reads lines, hands each to processLine
    super.readLines();
    scan.close();
writer.close();
   }

    public void processLine(String line){ // does the real processing work
     StringTokenizer st = new StringTokenizer(line);
     while (st.hasMoreTokens()) {
     String[] result = fileName.split("\\s");
     for (int x=0; x<result.length; x++)
         writer.print(result[result.length-x]);   
         writer.println("");
         //writer.print(st.nextToken());
         //writer.print(" ");
         
         
        
     }
writer.println("");
 
  }




}
Except in the file it prints the directory name liek C:\documents and settings\hello.txt a billion times. I thought the code would make each word backwards? But I'm totally confused anyone got any ideas?