reading a signel char in java

  • From: "Michael Malver" <mmalver@xxxxxxxx>
  • To: <programmingblind@xxxxxxxxxxxxx>
  • Date: Sat, 21 Nov 2009 20:33:00 -0600

Is there a way to get java to wait for a single key press.  This code gets a
key press, but won't print the char I typed until I hit enter

//this reads a char  of text.

import java.io.IOException;

class readchar{

 

public static void main (String args[]) throws IOException

{

System.out.println("Press any key.");

char c = (char) System.in.read();

System.out.println(c);

}

 

}

I want something that acts like getch() in c++. Sorry if I have the function
name wrong. It's been years since I've written c++ but you know what I mean
I think.

thanks

 

Other related posts:

  • » reading a signel char in java - Michael Malver