Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old May 25th, 2006, 8:53 AM   #1
sharadpro
Newbie
 
Join Date: Feb 2006
Location: India
Posts: 25
Rep Power: 0 sharadpro is on a distinguished road
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.
sharadpro is offline   Reply With Quote
Old May 25th, 2006, 9:12 AM   #2
Eric the Red
Hobbyist Programmer
 
Eric the Red's Avatar
 
Join Date: Feb 2006
Posts: 214
Rep Power: 0 Eric the Red is an unknown quantity at this point
What code do you have so far?
__________________
Death smiles at us all. All a man can do is smile back.
Eric the Red is offline   Reply With Quote
Old May 25th, 2006, 9:59 AM   #3
NSchnarr
Newbie
 
Join Date: May 2006
Posts: 28
Rep Power: 0 NSchnarr is on a distinguished road
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.
NSchnarr is offline   Reply With Quote
Old May 25th, 2006, 6:10 PM   #4
titaniumdecoy
Expert Programmer
 
titaniumdecoy's Avatar
 
Join Date: Nov 2005
Posts: 904
Rep Power: 3 titaniumdecoy is on a distinguished road
Send a message via AIM to titaniumdecoy
You could use a BufferedReader:
BufferedReader in = new BufferedReader(
                    new InputStreamReader(System.in));
titaniumdecoy is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 5:15 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC