Results 1 to 2 of 2
  1. #1
    tedstevens is offline Member
    Join Date
    Aug 2009
    Posts
    1
    Rep Power
    0

    Default Need help in knowing how to clear buffer.

    I'm trying to iterate over some statements until the user enters the letter 'n'.
    Java Code:
    		char answer;
    		BufferedReader BR = new BufferedReader(new InputStreamReader(System.in));
    Java Code:
    		do
    		{
                    .... //statements.
    		System.out.print("Continue? y/n _ ");
    		answer = (char) BR.next();
    		
    		}while (answer != 'n');
    I need to find a way to clear the buffer so that the character that gets entered does not interfere with the input statements inside the loop. Thanks.

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    There is no direct way to do this in Java. If you are worried about the memory and stuff, nothing to do there. Garbage collector will keep free the unnecessary memory allocations in your application. There is no guarantee each time, but 90% it's fine.

    What you mean by this?


    Quote Originally Posted by tedstevens View Post
    character that gets entered does not interfere with the input statements inside the loop

Similar Threads

  1. Knowing which IP address is active
    By sukatoa in forum Networking
    Replies: 2
    Last Post: 05-05-2009, 04:01 PM
  2. Need Help: Double Buffer
    By rukawa527 in forum AWT / Swing
    Replies: 1
    Last Post: 02-09-2009, 12:39 AM
  3. Buffer
    By QPRocky in forum Networking
    Replies: 2
    Last Post: 02-02-2009, 03:54 PM
  4. Help with String Buffer
    By mathias in forum AWT / Swing
    Replies: 1
    Last Post: 08-07-2007, 06:52 AM
  5. how to set the value of BUFFER SIZE
    By oregon in forum Advanced Java
    Replies: 1
    Last Post: 08-06-2007, 03:16 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •