NON Blocking Char Input
if from console set
#stty cbreak
the next program do not wait for <CR> after each keystroke.
// HOW to set system("stty cbreak"); inside the program?
===================================
import java.io.*;
class CharRead {
public static void main(String args[])
throws IOException
{
char c;
// system("stty cbreak"); ?!!!!!
System.out.println("'q' cancel.");
while( (c = (char) System.in.read() )!= 'q') {
System.out.println(c);
}
}
}
=============================
Much thanks for help.
[618 byte] By [
olafa] at [2007-10-3 2:24:44]

there were so many things wrong
public static void main(String[] args)
{
char c='x';
System.out.println("'q' cancel.");
try
{
c = (char) System.in.read();
}
catch (IOException e)
{
System.out.println(e);
}
while( c!= 'q')
{
try
{
c = (char) System.in.read();
}
catch (IOException e)
{
System.out.println(e);
}
}
}
}
public static void main(String[] args)
{
char c='x';
System.out.println("'q' cancel.");
while( c!= 'q')
{
try
{
c = (char) System.in.read();
}
catch (IOException e)
{
System.out.println(e);
}
}
}
}
no more duplicated code, there, fixed