This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes I/O and Streams and the fly likes Reading Through System.in Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "Reading Through System.in" Watch "Reading Through System.in" New topic
Author

Reading Through System.in

Satyajit Bhadange
Ranch Hand

Joined: May 13, 2010
Posts: 104


Using above code i am trying to read following input

1 10
100 200
201 210
900 1000

but it not reading last line of input.what is wrong with my code ?


Thanks
user101
Problems And Solutions - Algorithms
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38045
    
  22
I tried it and found no errors. Please explain more.
Satyajit Bhadange
Ranch Hand

Joined: May 13, 2010
Posts: 104
i am running code on eclipse.
I am copying input and pasting it into eclipse console.
while reading last line,it goes into infinte loop.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38045
    
  22
Does it really go into an infinite loop?

You do realise you have to give it a null line, which you do by entering the end-of-file character? On Windows® try ctrl-Z, on *nix try ctrl-D. If you don't give it an end-of-file, it always assumes it is at the start of a new line.
Satyajit Bhadange
Ranch Hand

Joined: May 13, 2010
Posts: 104
yes it doesn't go into infinite loop ,it just waits for user input .

and secondly ,what condition should go in while statement so that loop terminates even if there is no null given. ?
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38045
    
  22
Try changing the != null test to the isEmpty() ,method. Remember the bang operator ! before (s. Using String#isEmpty() will stop if you use the enter key twice.

Beware: it only works in Java6+. Otherwise you can try .length() > 0
Satyajit Bhadange
Ranch Hand

Joined: May 13, 2010
Posts: 104
Thank you
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Reading Through System.in
 
Similar Threads
Can't write to file
prog of multiple inputs
function in java similar to getch in C
System.in.read(byte b) not working?
method to read a string