Read Input from console !!!

Im am very new to java and trying to learn java ..
Now the problem i have is, I have to read input from console without using the BufferReader method..
Please tell me how to go about it..
I have a assignment to complete and im not able to figure out the way out.
Help ..

http://java.sun.com/j2se/1.4.1/docs/api/java/lang/System.html
Read first about the System class provided by Java.
Select the 'in' method of System class and it will take
you to the InputStream.
http://java.sun.com/j2se/1.4.1/docs/api/java/io/InputStream.html
An essay way of reading input is:
"value?"=System.in.read();
Try and see if this works. It will not use the
BufferReader portion, but it gives you another way
of reading from the console.

Similar Messages

  • Read characters from console.

    Hii
    I'm trying for 2 days to read characters from console on the fly, but it didn't work.
    I want to read each char that user press on line and without waiting for the Enter button. It's like an keyboard event but there is no GUI.
    I will appreciate any help.
    Thanks.

    I don't understund what you really want to do.it is possible mesure the time between each char type using the last code :
    char charPressed='\0';
    String line="";
    while(charPressed != '\n')
    try
    // start time
    charPressed =(char) System.in.read();
    line += charPressed;
    // end time
    // want to get out
    if(...) break;
    catch(IOException ioex) {ioex.printStackTrace();}
    Sorry, but your code doesn't measure the time between each char type.
    The function read waits for the "enter" key, and just after pressing enter your code will start to read all the chars you typed before "enter", so it won't do it.
    Read function will not help in this subject.

  • Make System.in read input from a command prompt

    How can i make System.in read input from a command prompt which is opened after program
    is started. Please note that program starts without commad promt. Can u plz help?
    sharmila

    System.in DOES read from the command shell that you start the app in.
    What you don't have is a prompt.
    You should know about Java Almanac. There are code samples for simple things like I/O that everyone should know about. There's an example there to help you.
    MOD

  • How to read input from handheld scanner on a keyboard port

    Hi everybody,
    i have an application that should read input from a scanner.
    If i use a jTextField to input scanned data it works fine.
    the problem is that i don't want to use any text component to input data into it.
    And if i set the jtextField not visible then the focus sustem doesnt work.
    I tried to read a buffered input stream from System.in but it doesnt work.
    If the scanner was installed on a serial port i could use javax.comm to monitor it.
    But unfortunately i must use the keyboard wedge thing...
    Do you have any ideas?
    Thank you in advance

    BufferedReader reader = new BufferedReader(new InputStreamReader(socket.getInputStream()))
    null

  • Reading inputs in console from user

    I wanted to know if its possible to capture inputs from user in console apps. Can you just do "System.in.read(variablename);" ????

    If you're just starting, I recommend that you learn to use the Scanner class methods. The class documentation has examples. It will read from the console, as well as any other source that exists, and allows much more flexibility. (The class is new whit Java 5.)

  • How to read char from console

    Hi can any body help me..
    I want to read char from keybord. withought pressing ENTER.
    I am not sure how i can do it. I can't use
    BufferedReader br = new  BufferedReader(new InputStreamReader ( System.in )) ;
    char key ;
    key = (char )br.read() ;
    cuz i have to press ENTER every time to read char.
    Thanks in advance.

    try this,I' have found a part on Internet
    package exercises;
    import java.io.BufferedReader;
    import java.io.InputStreamReader;
    * questa � la classe d' esempio per leggere l'input dalla console*/
    public class Echo {
    public static void main(String args[]) throws Exception{
    // This is where the magic happens. We have a plain old InputStream
    // and we want to read lines of text from the console.
    // To read lines of text we need a BufferedReader but the BufferedReader
    // only takes Readers as parameters.
    // InputStreamReader adapts the API of Streams to the API of Readers;
    // receives a Stream and creates a Reader, perfect for our purposes.
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    String input = "";
    while(true){
    System.out.print("ECHO< ");
    //As easy as that. Just readline, and receive a string with
    //the LF/CR stripped away.
    input = in.readLine();
    //Is a faster alternative to: if (input == null || input.equals(""))
    //The implementation of equals method inside String checks for
    // nulls before making any reference to the object.
    // Also the operator instance of returns false if the left-hand operand is null
    if ("".equals(input)){
    break;
    }else
    // Here you place your command pattern code.
    if ("ok".equals(input)){
    System.out.println("OK command received: do something �");
    //Output in uppercase
    System.out.println("ECHO> " + input.toUpperCase());
    System.out.println("ECHO> bye bye");
    //We exit without closing the Reader, since is standard input,
    // you shouldn't try to do it.
    // For all other streams remember to close before exit.
    }

  • Output while reading input in console

    im making a little console chat program, and i need to be able to send/receive, but, whenever a user is typing something in, nothing can get outputted. is there a way to do both at one time?

    u can go for two threads..one thread which reads the input from the console and write to the socket and another thread which reads from the socket and write to the console..
    i can give a simple implementation which is easy to understand and implement..mail me at [email protected]
    all the best
    sandeep

  • Keyboard input from console

    I have a swing GUI application which must show content reflecting to keyboard input.
    Input must be readed from System.in. When I type anything in console it works, but when
    I switch to GUI then keyboard input doesnt go to System.in. Any ideas how to solve this problem?
    Make keyboard input go to System.in while looking the GUI?
    Thank you in advance.

    I registred JFrame as keydispatcher and everything worked fine, except the fact that every keystroke got catched in dispatchEvent() three times.
    What concept am I missing? How to get one occurance of each keyevent?

  • Reading Binary from Console

    Hi all:
    I want to read the binary string from the console and do some manipulation with it. Can anyone please help?
    e.x Suppose i enter 0010 on my console and now i want read this as binary value
    and do some other manipulation with it. But i really don't know how i can read it?
    I am getting decimal value if i read it
    e.x suppose i entered 0010
    i will get 10 as value because i am reading it as integer not as binary. So iwant it as 0010 only.
    Thanks,
    Girish

    checking the range of this binary value (Range is 000000 -111111 ) read as suggested by suppechasper and check whether read value is between 0 and 64. if u read into say int x then
    if( x>0 && x <64 ){
                System.out.println("In the range");;
            }else{
                System.out.println("Out of the range");;
            }

  • Read input from user and strore in ztable

    Hai,
        could you please give some examples of How to read the input data from user and store in Ztable.
    Thanks

    Hi Prasanna,
    If i understood your requirement correctly,
    The below code will insert record in DB table as soon as you enter the value in two fields and press enter button .
    Go through the below code,
    <b>In Layout</b>
    <%@page language="abap"%>
    <%@extension name="htmlb" prefix="htmlb"%>
    <htmlb:content design="design2003">
      <htmlb:page title = "first page ">
        <htmlb:form>
          <htmlb:inputField  id="field1"/>
          <htmlb:inputField  id="field2"/>
          <htmlb:button       id="submitButton"  text = "Press Me"
                              onClick       = "myClickHandler" />
        </htmlb:form>
      </htmlb:page>
    </htmlb:content>
    <b>In Oninputprocessing event</b>
    CLASS CL_HTMLB_MANAGER DEFINITION LOAD.
      DATA: event TYPE REF TO CL_HTMLB_EVENT.
      data : begin of wa,
             matnr type mara-matnr,
             ersda type mara-ersda,
             end of wa.
      event ?= CL_HTMLB_MANAGER=>GET_EVENT( runtime->server->request ).
      IF event->id = 'submitButton' AND event->event_type = 'click'.
        DATA: data TYPE REF TO CL_HTMLB_INPUTFIELD.
        DATA: data1 TYPE REF TO CL_HTMLB_INPUTFIELD.
        data ?= CL_HTMLB_MANAGER=>GET_DATA( request = runtime->server->request
                                               name     = 'inputField'
                                               id       = 'field1'
        IF data IS NOT INITIAL.
         value = data->value.
          wa-matnr = data->value.
        ENDIF.
        data1 ?= CL_HTMLB_MANAGER=>GET_DATA( request = runtime->server->request
                                               name     = 'inputField'
                                               id       = 'field2'
        IF data1 IS NOT INITIAL.
         value = data->value.
          wa-ersda = data1->value.
        ENDIF.
       insert into ZAZAZ_BSP CLIENT SPECIFIED values wa.
      ENDIF.
    Regards,
    Azaz Ali.
    Don't forget to reward points.

  • Reading input from servlet works in Windows but not Kubuntu

    I'm working on an applet/servlet/mysql database application and recently switched from Windows Vista (yeah, yeah) to Kubuntu Gutsy Gibbon. In Vista, everything worked fine (bet you've never heard anyone say that before), but in Kubuntu, I get a FileNotFound exception at the line where I initialize the ObjectInputStream (the ObjectOutputStream line doesn't throw an exception, but it doesn't look like that one works either (I output queries and such to the log files when the servlet receives them, but the logs are empty)). I tried everything I could think of (tomcat is fine, the servlet is where it should be, etc), but nothing seems to work.
    Here's the code from my applet:
    //open the connection to the servlet
    URLConnection servletConnection = servletLocation.openConnection();
    //inform the connection that we will send output and accept input
    servletConnection.setDoOutput(true);
    servletConnection.setDoInput(true);
    //don't use a cached version of URL connection.
    servletConnection.setUseCaches(false);
    servletConnection.setDefaultUseCaches(false);
    //we will send java serialized objects
    servletConnection.setRequestProperty("Content-Type", "application/x-java-serialized-object");
    //send the object to the servlet using serialization
    //*THIS LINE DOESN'T THROW AN EXCEPTION*/
    ObjectOutputStream output=new ObjectOutputStream(servletConnection.getOutputStream());
    //serialize the object
    output.writeObject(data);
    output.flush();     
    output.close();
    //get the object input stream and receive a vector
    /*THIS LINE THROWS A FILENOTFOUND EXCEPTION*/
    ObjectInputStream input=new ObjectInputStream(servletConnection.getInputStream());               
    thing = input.readObject();
    input.close();
    As you can see, I use the same servletConnection for both the output as well as the input. I don't know why one would work and not the other.
    Any input would be great. Just to reiterate, it worked fine in Vista. I'm boggled.
    Thanks.

    If its a sand box restriction you should get a security restriction. How ever getting a FileNotFountException in an applet means that your code try to access a local file some ware which is not allowed in an applet unless it is signed.
    Give us the code that you use to create the URL object. You should not use hard coded URLs in an applet. You have to get the Document URL or Codebase URL of applet and then modify it to derive the URL of the servlet.

  • My Photoshop Elements 6.0 suddenly can't download plug-ins to read input from my cf photo card, or s

    My Photoshop Ele
    ments 6.0 suddenly stopped loading ph
    otos from my CF Card with the message that it could not download
    plug-ins to read the device.  It al
    ways worked before.  Would it help to re-install Elements, or should I look for a way to download the Plug-in.  Don't even know what it is called.  Thanks

    When you browse to Computer is your CF card shown as a removable drive?
    If not try shutting down the computer and re-starting and then inserting the CF card or plugging in the USB again.
    Open Elements Organizer and press Ctrl+G to bring up the downloader and under Source click refresh to locate your CF card.
      

  • How to read input from a file that is constantly being appended to?

    Hi -
    My problem is simple, yet very difficult to solve. There is a log file I want to read through, that is actively being written to by another program. I want to be able to block at the eof for more input, much like a network stream can block for more input. However, nothing works.
    Here is my snippet so far:
                int ch = '0';
                while( !terminate ) {
                    while( (char)ch != ']' ) {
                        ch = isr.read();
                        System.out.print((char)ch);
                    System.out.print("\n");
                }Terminate is just a control variable. isr is an InputStreamReader.
    The way the log file works is, the end of each line is denoted by a closing box-bracket. So I figured checking for that would be easy enough. The problem with that loop is, it keeps causing my IDE to hang when it runs... It will output the log file contents, but repeatedly, infinite times. I thought the read() method blocks when there is no more input?
    Is there anything else I can do to capture new appended text to this file?
    I've tried InputStreamReaders and FileInputStreams as well, and they all do the same thing.
    Thanks!
    -Josh

    Yes, I more or less do this. Now I simply open the BufferedReader a few bytes short of the file size (to save on memory usage) and then keep the buffer open. Then I just have the thread sleep for 500ms to not throttle the CPU through the roof. Then I merely check if the buffer does not equal null, if it doesn't, that means there is more stuff to process.
    I figure half a second delay maximum is practically realtime, and it is improv enough to do what I need to do.
    Thanks for the help.
    -Josh

  • Read key from console without blocking?

    I have a console application (a server) that needs to run in a loop till the user stops it (currently with Ctrl-C (ugh!)).
    How can I check to see if a key has been pressed (Enter is fine), and if not, just continue? I don't want to wait for a keypress, as System.in.read() does.
    The only thing I can think of is to put System.in.read() inside another Thread.
    There must be a standard way to solve this problem.
    Any suggestions?
    Thanks.

    Try thispublic class Test {
        public static void main( String args[] ) {
         int cnt=0;
         while (cnt<20) {
             try {
              if (System.in.available()>0) {
                  System.out.println("AV="+System.in.available());
                  while(System.in.available()>0) System.in.read();
              Thread.sleep(1000);
             } catch (Exception e) { e.printStackTrace(); }
             cnt++;
    }And the answer is, "There is no way to read single characters"

  • Keyboard input or Console Output

    I'm self teaching java... I got stuck with one of the exercises that is supposed to demonstrate the basic input and output through entering data on console...
    I went about writing the code as:
    public class Program2 {
    public static void main(final String [ ] args) {
    KeyboardInput in = new KeyboardInput () ;
    System.out.print ("Type your name: ") ;
    It doesn't compile:((((.... it says "KeyboardInput" is not a type...
    I would really appreciate if somebody could respond to this silly problem.

    For keyboard input from console the program would be
    public class Console{
      public static void main(String[] args){
        try{
          BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
          System.out.print("Enter Your Name: ");
          String name = reader.readLine();
          System.out.println("Your Name is "+name);
        }catch(Exception ex){
          ex.printStackTrace();
    }

Maybe you are looking for