/**
 * The stringy class implements an application that reads a
 * string from the keyboard, and then opens a file "a.txt"
 * and appends that string to that file (if filer.println
 * is chosen), otherwise it copies the string to the
 * screen (if screen.println is chosen).
 */

-----------------------------------------------------------

import java.io.*; 

public class stringy  // save as stringy.java
  { 
    public static void main(String [] args) throws Exception 
      { 
        final int MAX_SIZE = 10; 
        InputStreamReader isr   = new InputStreamReader ( System.in ); 
        BufferedReader inComing = new BufferedReader ( isr ); 
            // "true" in PrintWriter determines whether to "flush" the stream 
        PrintWriter screen      = new PrintWriter ( System.out , true ); 
            // "true" in FileOutputStream determines whether to append the text 
        FileOutputStream fos    = new FileOutputStream ( "a.txt" , true ); 
        PrintWriter filer       = new PrintWriter ( fos ); 
      
        String [] a = new String[MAX_SIZE]; 
        String temp = ""; 
        int count = 0; 
        int i = 0; 

        do 
          { 
            screen.println ( "Enter a string." ); 
            temp = inComing.readLine(); 
            if ( !temp.equals("") ) 
              a[i] = new String( temp ); 
            count = i++; 
          } while ( !temp.equals("") && (i < a.length) ); 

        for (i=0; i<count; i++) 
          screen.println(a[i]);  // make this filer.println to write to the file.

        filer.close(); 
      } 
  } 



-----------------------------------------------------------