Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / June 2007

Tip: Looking for answers? Try searching our database.

System.out.print() and BufferedReader.readLine()

Thread view: 
theirlaw - 06 Jun 2007 03:02 GMT
I currently have the following code:

public static void main(String[] args)
{
   InputStreamReader isr = new InputStreamReader( System.in );
   BufferedReader br = new BufferedReader( isr );

   String input = null;

   while ( true )
   {
       System.out.print( "Command: ");

       try
       {
           br.readLine();
       }
       catch ( IOException e)
       {}
   }
}

It compiles fine and makes complete logical sense to me. However, the
program seemingly skips over the System.out.print command and goes
right to waiting for input. This will continue to happen until the
loop is exited and then all of the "buffered" System.out.print
statements seem to just spit out.

Sample input looks something like:

Input1
Input2
Input3
<loop is exited here>
Command: Command: Command:

Can anyone explain this strange behavior? Thanks.
kcwong - 06 Jun 2007 03:50 GMT
> Sample input looks something like:
>
[quoted text clipped - 3 lines]
> <loop is exited here>
> Command: Command: Command:

Works correctly for me. I got:

Command: Input1
Command: Input2
Command: Input3

> Can anyone explain this strange behavior? Thanks.

What environment are you running your program in? Inside an IDE?
theirlaw - 06 Jun 2007 05:32 GMT
> > Sample input looks something like:
>
[quoted text clipped - 13 lines]
>
> What environment are you running your program in? Inside an IDE?

Yes, it is within NetBeans. I was suspicious that NetBeans' console
was causing the issue. I will compile and execute outside of the IDE.
Thanks!


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.