import java.util.Scanner;
import java.io.*;

public class ReadFromAndWriteToFile2
{
  public static void main (String [] args) throws IOException
  {
     Scanner myInputFile;
	  String myInputFileName, myOutputFileName;
	  FileWriter myFileWriter;
	  BufferedWriter myBufferedWriter;
	  PrintWriter 	myPrintWriter;
	  int count;
	  String temp;
	  
	  count = 0;
	  myInputFileName = "text.in";
	  myInputFile = new Scanner (new File(myInputFileName));
	  
	  myOutputFileName = "text.out";
	  myFileWriter = new FileWriter (myOutputFileName);
	  myBufferedWriter = new BufferedWriter (myFileWriter);
	  myPrintWriter = new PrintWriter (myBufferedWriter);
	  
	  while (myInputFile.hasNext())
	  {
	     temp = myInputFile.nextLine();
		  count++;
		  System.out.println (" picked up " + temp + " from the file");
		  myPrintWriter.println (temp + " " + count);
	  }
	  
	  myPrintWriter.close ();
	  System.out.println (" Read from file " + myInputFileName);
	  System.out.println (" Wrote to file " + myOutputFileName);
	  System.out.println (" There were " + count + " words in the file. ");
	}
}	  