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.
}

Similar Messages

  • 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.

  • 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.

  • [Urgent] How to read files from different directories?

    I am new to Java Programming, I would like to know how to read files from directories other than the current one? (example as follows)
    ProjectDirectory
    |--MainDirectory
    |--MainProgram.java
    |--SupplementDirectory
    |--SupplementProgram.java
    |--Pictures
    |--Image.gif
    What should I write in the MainProgram.java so that I can use the supplementProgram.java from MainProgram and read the Image.gif file from the MainProgram.java?
    Thanks

    Run through the I/O tutorial here. It should get you up to speed on this sort of thing...

  • How to read data from a CLUSTER STRUCTURE not cluster table.

    Hi,
    how to read data from a CLUSTER STRUCTURE not cluster table.
    regards,
    Usha.

    Hello,
    A structre doesnt contain data.. so u cannot read from it. U need to find out table of that structure and read data from it.
    Regards,
    Mansi.

  • How to read data from a file that was formatted by excel?

    Hi everyone, I'm familiar with java.io and the ability to read from files, can anyone tell me how to read data from a file that was formatted by excel? Or at least give me some web references so that I can learn about it?

    http://jakarta.apache.org/poi/hssf/index.html
    HSSF stands for Horrible Spreadsheet Format, but it still works!

  • How to read data from a router by using labview

    I am a  beginner labview. How to read data from a router by using labview ? 

    What kind of data are you trying to read?
    Does the router behave like a webserver that you log into?  If so, search the forums for threads discussing HTML.

  • How to read data from a connected modem

    any one can help me? how to read data from a connected modem. The modem received real-time data from other server. The data is in text format. I can see this text when I used hyperterminal for dial up and the data is accumulated such as:
    @aa1235678
    @bb2135647
    @cc5214367
    since it is real-time data, I want to read one line each time instantly when it arrives.

    You need to use the Java Communications API. (http://java.sun.com/products/javacomm/index.html)

  • How to read data from a zipped MS Access file?

    How to read data from a zipped MS Access file?

    RPJ,
    You do not need to use the Close Zip File.vi when you unzip a folder.  This VI is used when you are creating a zip folder.
    As for examples, I found a couple of ActiveX based MS Access examples.  These programs look to be pretty basic.  For more in depth example I would search Microsoft Developers Network
    http://zone.ni.com/devzone/cda/epd/p/id/2188
    http://zone.ni.com/devzone/cda/epd/p/id/1694
    Regards,
    Jon S.
    National Instruments
    LabVIEW R&D

  • How to read data from an internal table into a real table?

    Hello experts,
    I'm relatively new to ABAP and I'm trying to figure out how to read data from an internal table into a table that I created.  I'm trying to use the RRW3_GET_QUERY_VIEW_DATA function module to read data from a multiprovider.  I'm trying to read data from the e_cell_data and e_axis_data tables into a table that I've already created.  Please see code below.
    TABLES MULTITAB.
    DATA:
      query_name TYPE RSZCOMPID,
      s_cubename TYPE RSINFOPROV,
      t_cell_data TYPE RRWS_T_CELL,
      t_axis_data TYPE RRWS_THX_AXIS_DATA,
      t_axis_info TYPE RRWS_THX_AXIS_INFO,
      wa_t_cell_data like line of t_cell_data,
      wa_t_axis_data like line of t_axis_data,
      w_corp_tab like line of t_cell_data.
    s_cubename = 'CORP_MPO1'.
    query_name = 'Z_corp_test'.
        CALL FUNCTION 'RRW3_GET_QUERY_VIEW_DATA'
           EXPORTING
             i_infoprovider           = s_cubename
             i_query                  = query_name
            i_t_parameter            = query_string_tab
           IMPORTING
             e_cell_data              = t_cell_data
             e_axis_data              = t_axis_data
             e_axis_info              = t_axis_info.
    If anyone has any information to help me, I would greatly appreciate it.  Thanks.

    Hi,
    <li>Once you call the function module RRW3_GET_QUERY_VIEW_DATA, lets say data is available in the corresponding tables e_cell_data e_axis_data which you have mentioned.
    <li>Modify your internal table defined for other purpose, with data from e_cell_data e_axis_data like below.
    LOOP AT t_cell_data INTO wa_t_cell_data.
      "Get the required data from t_cell_data.
      MOVE-CORRESPONDING wa_t_cell_data TO it_ur_tab.
      "Modify your internal table wih data
      MODIFY it_ur_tab TRANSPORTING <field1> <field2> <field3>.
    ENDLOOP.
    LOOP AT t_axis_data INTO wa_t_axis_data.
      "Get the required data from t_cell_data.
      MOVE-CORRESPONDING wa_t_axis_data TO it_ur_tab.
      "Modify your internal table wih data
      MODIFY it_ur_tab TRANSPORTING <field1> <field2> <field3>.
    ENDLOOP.
    Thanks
    Venkat.O

  • How to read HyperLinks from pdf file??

    hi developer's,
    I am in PDF processing... I am having doubt in that Processing.
    How to read Hyperlinks from PDF file?
    I can able to set the hyperlink.. But i cant able to get the hyperlinks..
    The following example program will set the hyperlink to the PDF file using lowagie API..
    import com.lowagie.text.Anchor;
    import com.lowagie.text.Chunk;
    import com.lowagie.text.Document;
    import com.lowagie.text.DocumentException;
    import com.lowagie.text.Paragraph;
    import com.lowagie.text.html.HtmlWriter;
    import com.lowagie.text.pdf.PdfReader;
    import com.lowagie.text.pdf.PdfWriter;
    public class Argu1 {
         public static void main(String[] args) {
              Document document = new Document();
              try {
                   PdfWriter pdf = PdfWriter.getInstance(document,
                             new FileOutputStream("PageLink.pdf"));
    PdfReader pdf_read=new                
                   document.open();
                   document.add(new Paragraph("Hi Everbody....!"));
                   Anchor pdfRef = new Anchor("Click Me");
                   pdfRef.setReference("www.java2s.com");
                   Anchor rtfRef = new Anchor("Touch Me");
                   rtfRef.setReference("www.sun.com");
                   System.out.println(rtfRef.reference());
                   document.add(pdfRef);
                   document.add(Chunk.NEWLINE);
                   document.add(rtfRef);
              } catch (DocumentException de) {
                   System.err.println(de.getMessage());
              } catch (IOException ioe) {
                   System.err.println(ioe.getMessage());
              document.close();
    Help me how to read the Hyperlinks from the PDF file using java ...
    Thanks in advance,
    With Regards,
    J.Imran

    Instead of cross-posting unformatted code you could have taken a look at the API, because there you might have come across a method named getLinks...Even though it's not documented, I really suspect that it will return the Hyperlinks on a given page.

  • Help me,  How to read data from USB ???

    Help me, How to read data from USB ???

    If its a disk on key or some portable hard drive than once its connected to the usb and recognized by the system you can access it through java like you would access your hard drive.

  • Best way to read chars from InputStream

    Hope this is not a too newbie question.
    Suppose I have an unbuffered InputStream inputStream, what is the best way to read chars from it (in terms of performance)?
    Reader reader = new BufferedReader(new InputStreamReader(inputStream));
    reader.read()
    or
    Read reader = new InputStreamReader(new BufferedInputStream(inputStream))
    reader.read()
    Is there a difference between the two and if so, which one is better?
    thanks.

    If you are reading using a buffer of your own, then adding a buffer for binary data is a bad idea.
    However for text, using a BufferedInputStream could be better as it reduces calls to the OS.
    If it really matters, I suggest you do a simple performance test which runs for at least a few seconds to see what the difference is. (You should runt he test mroe than once)
    Edited by: Peter__Lawrey on 20-Feb-2009 21:37

  • Reading char from keyboard to stop threads?

    I want to kill all the threads an terminate my program execution when I enter some char, for example 'S'.
    BUT, I dont want the execution flow to wait in the sentence 'prompt.read()' until I enter some character.
    does somebody knows the solution?
    this is my program:
    import java.io.*;
    public class Finalizadora extends Thread {
         public static boolean ejecucion = true;
         public void run() {
              while (ejecucion) {
                   try {
                        sleep(1000);
                   } catch (Exception e) {
                        // Si falla el sleep lo simulamos
                        for (int i = 0; i < 1000 * 10; i++) {
                        } // fin del for
                   } // fin del try
                   try {
                        BufferedReader prompt = new BufferedReader(new InputStreamReader (System.in));
                        if (prompt.read() == 'S') {
                            ejecucion = false;
                        } // fin del if
                   } catch (Exception e) {
                        System.out.println("SOME FAILS!!");
                   //System.out.println("--------------------");
              } // fin del while
              System.out.println("ENDING...");          
         } // fin de parsear
    } // fin de Finalizadorathanks!

    Hello.I cant read chars from a file.I am trying to fing to character with Max Occurrence in a file but when I run it it stops abruptly.This is my code.Can you help me please.Thank you
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    * @author Dimitrios
    /*Assuming that the char with the max frequency in an standard English test is 'E' we can guess
    * that the char with the max frequency in the cipher text is E.This will
    * lead us to an approximation of the Key by shifting */
    import java.io.*;
    public class Frequency_Decprypt {
    public static int Occurrence(String str, char ch) {
    int occur=0;//the occurrence of char ch in the string
    for(int i=0;i<str.length();i++){
    if(str.charAt(i)==ch){
    occur++;
    return occur;
    public static char Frequency() throws IOException{
    BufferedReader in;
    FileReader fr;
    int key=0;
    char Max_FreqChar=' ';//the char with the max frequency
    int Max_Freq=0;// the max frequency of a char
    try{
    fr=new FileReader("Encrypted.txt");//the input file to read
    in=new BufferedReader(fr);
    //read a line from file
    String s=in.readLine();
    while(s!=null){
    for(int i=0;i<s.length();i++){
    if(Occurrence(s,s.charAt(i))>=Max_Freq){
    Max_Freq=Occurrence(s,s.charAt(i));
    Max_FreqChar=s.charAt(i);
    s=in.readLine();
    fr.close();
    //key=(int)('e'-Max_FreqChar);
    //key=Math.abs(key);
    } catch (FileNotFoundException e)
    { System.out.println("File not found");}
    return Max_FreqChar;
    }

  • How to read values from DMM4040

    Hi,
       I am using DMM4040, NI PXI 6509 device.
    I need to make some port pins high which i have already done and now i have to read value captured by DMM then i have to make my port pins low if my value is within limits.
    Can u suggest me how to read values from DMM and then by notification i ll make my port pins low.
    '' A professional is someone who can do his best work when he doesn't feel like it''...........

    What language are you using?  If using LabVIEW, you use the NI-DMM API to communicate with the 4040.  Just take your reading, do your limit comparison, and set your lines based on the comparison results.
    There are only two ways to tell somebody thanks: Kudos and Marked Solutions
    Unofficial Forum Rules and Guidelines

Maybe you are looking for

  • Adobe Bridge CC keeps stalling

    Adobe bridge keeps crashing. Whenever I open bridge, it asks me to purge my cache, which I do. After viewing my folders for a while, and it doesn't matter which hard or folder I view ( I use multiple hard drives depending on the project and client),

  • Nokia mix radio subscription

    How to redeem Nokia music store subscription??? I tried to subscribe using oxicash,but can't have the access.then i walked to Nokia care and they are saying their web site is having some errors.. :'( What should I do???

  • AP 2602 Problem with Code 7.4.100.60

    Hi at all, I have problems with the code 7.4.100.60 and 2602 AP´s. The AP´s stops delivering services and no client can connected to them. After a reboot all problems are solved, but this problem comes back every ten days. In the logs are only shown

  • Process a text file?

    hi..   How 2 process a text file? bye.

  • Outlook 2007 PDF preview on Windows Server 2003?

    Simple question. Does the new (Reader 8.1) PDF Preview feature for Outlook 2007 work in Windows Server 2003? Or is it only for XP and Vista? The patch notes strongly suggest the latter, but in other places (such as a blog on this site) there are note