import java.io.*;

/*******************************************************************************
 * Read from console, and write to a file using char (16 bit) I/O 
 *    
 * If output file does not exist, it creates one
 *
 * Instantiate an InputSreamReader to convert 8bit byte read to 16bit char read
 * Instantiate a  BufferedReader to buffer the input
 *
 * Instantiate a File to get a file handle to the phsical file.
 * Instantiate a FileWriter  to open the file for output.
 * Instantiate a PrintWriter to buffer the print operation. 
 *******************************************************************************/

public class IOfile2b
{
    public static void main(String[] args)
    {

        String output_file = "../data/temp2.txt";					//relative path 

//      String output_file = "/home/sultans/web/java/demo/8inpout/data/temp2.txt"; 

        try 
        {
            InputStreamReader keyboard  = new InputStreamReader(System.in);  //8bit to 16bit
            BufferedReader    keyBuf    = new BufferedReader(keyboard);      //buffer the read

            File        file1     = new File(output_file);              //create a file handle
            FileWriter  outFile   = new FileWriter(file1);              //open file1 for output
            PrintWriter outBuffer = new PrintWriter(outFile);           //buffer the output

            System.out.println("Enter muliple lines, when done press <Enter>");

            while(true)
            {
                String input = keyBuf.readLine();               //read a line from keyboard

                if (input.equals("") )                          //empty line
                    break;

                outBuffer.println(input);                       //write the line
            }

            outFile.close();                                    //close output file handle
        }
        catch (IOException e)
        {
            System.out.println(e);
        }           
    }
}