jGuru
Register Email     Password Forgot your
password?
HOME FAQS FORUMS DOWNLOADS ARTICLES PEERSCOPE LEARN

  Search   jGuru Search Help

Question How do I read text from standard input?
Topics Java:API:IO
Author John Zukowski PREMIUM
Created Jul 9, 2000 Modified Aug 18, 2001


Answer
System.in is the InputStream for standard input. The following demonstrating reading from it a line at a time:
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader reader = new BufferedReader(isr);
String line = null;
while ((line = reader.readLine()) != null) {
 // Process line
}


Is this item helpful?  yes  no     Previous votes   Yes: 1  No: 0



Comments and alternative answers

Comment on this FAQ entry

How do I read text from standard input?
ron london, Dec 10, 2001

One of the limitations of using the

read()
method with standard input
System.in
is that it waits for a new line to be entered before returning the contents of the stream. In spite of this, it can still be useful in Java console applications.



Is this item helpful?  yes  no     Previous votes   Yes: 0  No: 0



Reply to this answer/comment  Help  


Ask A Question



 
Related Links

IO FAQ

IO Forum

I/O in Java 2 SDK

Java I/O package documentation

Lesson: Reading and Writing (Sun Tutorial)

jGuru Serialization FAQ

Wish List
Features
About jGuru
Contact Us

 



The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers