Use a DataInputStream to read characters from the console

/* Use a DataInputStream to read characters from the console */

import java.io.DataInputStream;    // load class for reading purpose

class ReadDemo1
{
    public static void main(String args[ ])
    {
        // creating object of class DataInputStream.
                   DataInputStream in = new DataInputStream(System.in);   
                   char c;

        try
        {
            System.out.println("Enter character 'E' to Exit : ");
            // read characters
            do
            {
                c = (char)in.read();
                System.out.println(c);       
            }while(c!='Q');
       
        }
          catch(Exception e)
                { 
                          System.out.println("I/O Error");
                }
    }
}   

0 comments:

Post a Comment

 
 
 
 


Copyright © 2012 http://codeprecisely.blogspot.com. All rights reserved |Term of Use and Policies|