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]
# 1
Please use the [url> http://forum.java.sun.com/help.jspa?sec=formatting]Code Formatting Tags[/url].
zadoka at 2007-7-14 19:23:44 > top of Java-index,Java Essentials,New To Java...
# 2

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);

}

}

}

}

PlasmaLinka at 2007-7-14 19:23:44 > top of Java-index,Java Essentials,New To Java...
# 3
> there were so many things wrongLike duplicating code perhaps?
floundera at 2007-7-14 19:23:44 > top of Java-index,Java Essentials,New To Java...
# 4

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

PlasmaLinka at 2007-7-14 19:23:44 > top of Java-index,Java Essentials,New To Java...