import java.io.*;

/**
 * Read and write to console using Byte (8 bit) I/O  
 * This program reads "unbuffered" data using streams
 * Program terminates if user enters an empty line
 */

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

        System.out.println("Read unbuffered 8bit array, convert to string, & write");

        byte[ ] array    = new byte[250];                   //create a byte array
        byte newlineUnix = '\n';                            //value 13
        byte newlinePC   = '\r';                            //value 10

        try 
        {
            while(true)
            {
                System.out.print("Enter something: ");

                int numBytes = System.in.read(array);           //read from console
                                                                //return number of bytes read
                byte firstChar = array[0];
     
                if (firstChar=='\n' || firstChar=='\r')         //carriage return or line feed
                    System.exit(0);

                String input = new String(array, 0, numBytes);  //create a new String from an array
                                                                //with offset 0, for number of bytes
                System.out.print("You've entered.: "+ input);

            }
        }
        catch (IOException e)
        {
            System.out.println(e);
        }
    }
}