![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Feb 2006
Location: India
Posts: 25
Rep Power: 0
![]() |
flushing input buffer
how can the input buffer be flushed ??
wats the function and its syntax? thank you!! class MenuD
{
public static void main(String args[])
throws java.io.IOException
{
char choice;
do
{
System.out.println("Menu :");
System.out.println("1.Hello");
System.out.println("2.Abc");
System.out.println("3.Exit");
System.out.println("Enter choice");
choice = (char) System.in.read();
switch(choice)
{
case '1':
System.out.println("Hello");
break;
case '2':
System.out.println("Abc");
break;
case '3' :
System.out.println("Exiting.....");
break;
}
} while(choice!='3');
}
}i want to flush the buffer after the value of choice is entered!! Last edited by sharadpro; May 25th, 2006 at 9:18 AM. |
|
|
|
|
|
#2 |
|
Hobbyist Programmer
Join Date: Feb 2006
Posts: 214
Rep Power: 0
![]() |
What code do you have so far?
__________________
Death smiles at us all. All a man can do is smile back. |
|
|
|
|
|
#3 |
|
Newbie
Join Date: May 2006
Posts: 28
Rep Power: 0
![]() |
I know you could use the scanner class, thats what i usually use when dealing with i/o. Not sure if this would help but you could try.
InputStream in = new InputStream(); System.setIn(in); this is supposed to set a new input stream, and therefore, not use the old one. Just use the scanner class tho. |
|
|
|
|
|
#4 |
|
Expert Programmer
|
You could use a BufferedReader:
BufferedReader in = new BufferedReader(
new InputStreamReader(System.in)); |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|