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.

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.

  • Reading characters from a text file into a multidimensional array?

    I have an array, maze[][] that is to be filled with characters from a text file. I've got most of the program worked out (i think) but can't test it because I am reading my file incorrectly. However, I'm running into major headaches with this part of the program.
    The text file looks like this: (It is meant to be a maze, 19 is the size of the maze(assumed to be square). is free space, # is block, s is start, x is finish)
    This didn't paste evenly, but thats not a big deal. Just giving an idea.
    19
    5..................
    And my constructor looks like follows, I've tried zillions of things with the input.hasNext() and hasNextLine() to no avail.
    Code:
    //Scanner to read file
    Scanner input = null;
    try{
    input = new Scanner(fileName);
    }catch(RuntimeException e) {
    System.err.println("Couldn't find the file");
    System.exit(0);
    //Set the size of the maze
    while(input.hasNextInt())
    size = input.nextInt();
    //Set Limits on coordinates
    Coordinates.setLimits(size);
    //Set the maze[][] array equal to this size
    maze = new char[size][size];
    //Fill the Array with maze values
    for(int i = 0; i < maze.length; i++)
    for(int x = 0; x < maze.length; x++)
    if(input.hasNextLine())
    String insert = input.nextLine();
    maze[i][x] = insert.charAt(x);
    Any advice would be loved =D

    Code-tags sometimes cause wonders, I replaced # with *, as the code tags interprets # as comment, which looks odd:
    ******...*.........To your code: Did you test it step by step, to find out about what is read? You could either use a debugger (e.g., if you have an IDE) or system outs to get a clue. First thing to check would be, if the maze size is read correctly. Further, the following loops look odd:for(int i = 0; i < maze.length; i++) {
        for(int x = 0; x < maze.length; x++) {
            if (input.hasNextLine()) {
                String insert = input.nextLine();
                maze[x] = insert.charAt(x);
    }Shouldn't the nextLine test and assignment be in the outer loop? And assignment be to each maze's inner array? Like so:for(int i = 0; i < maze.length; i++) {
        if (input.hasNextLine()) {
            String insert = input.nextLine();
            for(int x = 0; x < insert.size(); x++) {
                maze[i][x] = insert.charAt(x);
    }Otherwise, only one character per line is read and storing a character actually should fail.

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

  • How to read characters from a string ?

    Hi,
    In my java program I accepted string from the user and now I want to calculate the length of the string, and then read characters one by one to encrypt it.
    How to read the characters one by one ? Like Mid$ function in VB.
    Small code to illustrate will be appreciated.

    Hi,
    Pick one!
    public class A
      public static void pokeAtString( String s )
        for( int i = 0; i < s.length(); ++i )
          System.out.print( s.charAt( i ) );
      public static void useCharArray( String s )
        char[] c = s.toCharArray();
        for( int i = 0; i < c.length; ++i )
          System.out.print( c[i] );
      public static void main( String[] args )
        String s = "Once was a good man.";
        System.out.print( "PokeAtString: " );
        pokeAtString( s );
        System.out.print( "\nuseCharArray: " );
        useCharArray( s );
        System.out.println( "" );
    }Enjoy,
    Manfred.

  • Reading Characters From Car Number Plate

    hi ,
    In my application i need to read the car number from Number Plate.
    For that i used OCR to read the characters from car image.
    I can read the characters from the image if the images very clear.
    If the Car number is in some different format i couldn't read the exact number ,instead i'm getting some unwanted characters.
    the following is my code
    BufferedImage image = ImageIO.read(new File("2018.jpg"));
    image = image.getSubimage(100,120,200,120);
    String s = new OCR().recognizeCharacters(image);Please give me some suggestion.

    jwenting wrote:
    and don't forget that the image may well contain more text than just the license number...
    Most license plates are placed in a bracket with the dealer name and address, US plates have the name of the state they're issued in (and so possibly do other countries), EU plates have the international code for the country they're issued in, some countries (like Germany) have stickers on them to indicate the exact issueing location and/or latest government mandated checks on the car), etc. etc.... and you might also see a Swedish license plate in another country. We like to travel (but why bring the car?)

  • Reading characters from the console, ONE AT A TIME

    I'm writing a small Java program that will have a command line interface
    (sort of a 'shell').
    The thing is, that I want to recognize special keys being pressed by the
    user. No matter what I tried (System.in.read(); for example), it gives the
    characters one by one, all right, but only after the <ENTER> key is
    pressed!!!
    Is there a way to REALLY get the keys immediately when the user presses
    them?
    Thanks
    u.s

    If you're willing to have your own window, you can attach a KeyListener to a Component. I don't know how to do it in console mode.

  • How to read characters from a text file in java program ?

    Sir,
    I have to read the characters m to z listed in a text file .
    I must compare the character read from the file.
    And if any of the characters between m to z is matched i have to replace it with a hexadecimal value.
    Any help or suggesstions in this regard would be very useful.
    Thanking you,
    khurram

    Hai,
    The requirement is like this
    There is an input file, the contents of the file are as follows, you can assume any name for the file.
    #Character mappings for Japanese Shift-JIS character set
    #ASCII character Mapped Shift-JIS character
    m 227,128,133 #Half width katakana letter small m
    n 227,128,134 #Half width katakana letter small n
    o 227,129,129
    p 227,129,130
    q 227,129,131
    r 227,129,132
    s 227,129,133
    t 227,129,134
    u 227,129,135
    v 227,129,136
    w 227,129,137
    x 227,129,138
    y 227,129,139
    z 227,129,142
    The contents of the above file are to be read as input.
    On encountering any character between m to z, i have to do a replacement with a hexadecimal code point value for the multibyte representation in the second column in the input file.
    I have the code to get the unicode codepoint value from the multibyte representation, but not from a file.
    So if you could please tell me how to get the characters in the second column, it would be very useful for me.
    The character # is used to represent the beginning of a comment in the input file.
    And comment lines are to be ignored while reading the file.
    Say i have a string str="message";
    then i should replace the m with the unicode code point value.
    Thanking you,
    khurram

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

  • The best way to read characters from a single line?

    my problem is i have is that 0-5 characters are on one line i need to split this up as each single letter stands for a word i.e - f = football. i need to separate each one. also a person can have up to five hobbies (the letters stand for likes or dislikes) so i also need to think about making sure a reader? stops after the line ends.
    any ideas on the best, most efficient method i could use to overcome this problem?
    thank you Aaron.

    String letters = "fgdat";
    char[] characters = letters.toCharArray();Try that out.

  • Problem while reading Characters from Vacuum fluorescent Display(VFD) of DVD using OCR

    Hi,
    Happy New Year!!!!
    I am using PXI-1409 card to read the Vacuum fluorescent Dispaly(VFD) of a DVD using an analog CCD camera. Pl. see the attached bmp file. My objective is to recognize all the characters in the first line(CD 0:02 MP3"), IInd line (SHUFFLE REPEAT DISC) and the third line(SHUFFLE REPEAT DISC) including as many no. of spaces in between. My program has to automatically locate all the three lines. I have trained an OCR file to read all the possible characters many times. Also I have set the acceptance level as 720 and theshold limits (40-255), Read Resolution as Low and other various settings in OCR file. I am able to read all the characters 90% of the time but sometimes I am not able to recognize the right characters, for e.g it reads
    H as M
    or M as N
    or zero as 'O'
    or F as P etc. I have trained all the characters more than one time. I want my program to be 100% reliable and repeatable. I have tried all the methods to obtain it but still it not 100% perfect.
    Kindly suggest the best method to obtain it.
    Thanx in advance.
    Nirmal Sharma

    I am sorry, bmp file could not be attached last time. I m doing it now.
    Thanx
    Nirmal
    Attachments:
    im0212.bmp ‏283 KB

  • Message (on one account) when logging in: The user account running the Configuration Manager console has insufficient permissions to read information from the Configuration Manager site database.

    After installing the reportservice/database i cannot use the Configuration Manager Console 2012 anymore with my own AD account. (The accounts of my colleagues are stil working)
    When i login i get the following message:
    The user account running the Configuration Manager console has insufficient permissions to read information from the Configuration Manager site database. The account must belong to a security role in Configuration Manager. The account must also have
    the Windows Server Distributed Component Object Model (DCOM) Remote Activation permission for the computer running the Configuration Manager site server and the SMS Provider.
    I checked the following:
    I am a administrative user in SCCM (Full Administrator)
    I am a member of the administrator group on the server
    Deleted HKEY_CURRENT_USER\Software\Microsoft\ConfigMgr10
    I tried to start it on multiple workstations and deleted my roaming profile
    Any more suggestions?

    Hi,
    Maybe you could have a look on the below blog.
    http://blog.nimbo.com/how-to-disable-user-account-control-in-windows-server-2012/
    (Note: Microsoft provides third-party contact information to help you find technical support. This contact information
    may change without notice. Microsoft does not guarantee the accuracy of this third-party contact information.)
    Best Regards,
    Joyce Li
    We
    are trying to better understand customer views on social support experience, so your participation in this
    interview project would be greatly appreciated if you have time.
    Thanks for helping make community forums a great place.

  • Reading in a certain number of characters from a file.

    Hi guys,
    I need some pointers on how to read in a specified number of characters from a text file.For example,how would I read in the first 100 characters to an array from a text file with an unspecfied number of characters (more than 100 rather than less!).
    At present I am getting code errors being thrown due to reading in beyond the array size ie
    java.lang.ArrayIndexOutOfBoundsException: 100.

    post more code , this exception tells me nothing
    without seeing what you are actually doing.
    public String getText (String file)//textfile to be analyzed will be inputted as argument 150407 0356
       //15042007 0612 Check notes on overloaded getText method below.
           int temp;
           inputFile = file;
           int i=0;
                try
                    BufferedReader bGetFile = new BufferedReader (new FileReader(inputFile));
                    while ((temp=bGetFile.read())!=-1)
                        textFromFile[i] = (char)temp;
                        i++;
                    /*for (int j=0;j<MAX;j++)
                        System.out.print(textFromFile[j]);//25042007 0208.For Testing purposes
                    inputText=new String(textFromFile).trim();
                    bGetFile.close();
                catch (IOException e)
                    System.out.println (" ");
                    System.out.println ("Sorry.An error occurred while trying to read from the input file.Unable to proceed!");
                System.out.println ("Processing the input text file "); //25042007 2318 being used for debugging purposes.          
                return inputText;
        }If the file being read is greater than MAX characters it will throw the exception mentioned.What I would like to do is read in MAX characters and discard the rest.

  • Error reading data from the MS Dos Console.

    Hi,
    We have a legacy application which is launched via a 3rd-party Telnet Server - the app acts as a remote shell for an RF device. The system has been functioning for many years but now we have migrated to Server 2012 the system no longer launches.
    The RF device successfully connects to the telnet server, logs-in with embedded credentails but drops the connection when the shell application is launched.
    The server has the following Application error
    Error reading data from the MS Dos Console.
    The pipe has been ended. 109 (0x6d)
    The application can successfully be launched locally outside of the shell on the server. The error is reproducable across RF devices and desktop telnet connections.
    The firewalls are off.
    Are there some additional protections in Server 2012 which would cause the pipe-based link to be stopped when launching the exe? Am I missing something? The 3rd-party telnet server is certified for Server 2012.
    Thnak you

    I'd ask in the
    Windows Server General Forum, or ask the third party vendor.
    Karl
    When you see answers and helpful posts, please click Vote As Helpful, Propose As Answer, and/or Mark As Answer
    My Blog: http://unlockpowershell.wordpress.com
    My Book:
    Windows PowerShell 2.0 Bible
    My E-mail: -join ("6B61726C6D69747363686B65406D742E6E6574"-split"(?<=\G.{2})",19|%{[char][int]"0x$_"})

Maybe you are looking for

  • Error while provisioning OIM - AD in SSL

    Hi All, I am trying to configure OIM - AD communication in SSL mode. for that, I installed the AD connector MSFT_AD_Base_91100 and i deployed it. It was successfully configured. and my OIM version is OIM9101. I configured the IT Resource by mentionin

  • How can I view a wmv attachment

    I get many emails with wmv attachment. How can I view them? Is there an Ipad App that solves this? Thanks Marc

  • Viewing pictures on the TV

    I synchronized my pictures to my ipod using itunes. I connected my ipod to the TV (red to red etc.) using an ipod AV cable. I tried setting the TV to video 1 and also video 2 but got no image on the TV.Is there something I should be doing in the slid

  • Application runs slower on Solaris

    We have developed an Application in Java (Servlets, JSP & Core Java classes including thread). My Application runs fast on Windows, but its terribly slow on Solaris. When the application is run on Solaris the CPU usage is very less around 3 to 5 % on

  • To small appearance of the SAP Transaction Callable Object

    Hello, I use a Callable Object of the type SAP Transaction in my Guided Procedures process. The problem is, that the resulting iView is only about 100px high. This appearance is not realy usable. Is there any possibility to modify the responsible app