Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

nothing printed  RSS feed

 
Michael.H.Sun
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can anyone tell me why there is nothing printed from the following? Thanks.

package package1;
import java.io.*;
class reader
{
public static void main (String args[]){
try{
int character;
InputStreamReader inputstreamreader = new
InputStreamReader (System.in);
while ((character = inputstreamreader.read()) !=-1) {
System.out.print((char) character);
}
}
catch (IOException e) {}
}
}
 
Thomas Paul
mister krabs
Ranch Hand
Posts: 13974
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It works fine. Are you aware that nothing gets read until the enter key is pressed?
 
Susan Hoover
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The program is worked properly[1].
You have specified System.in as your input stream. By default, System.in refers to the console, i.e. your keyboard generates the input. If you run your example program and then type some text followed by Return/Enter, the text you typed will be echoed to the screen (where System.out refers by default). To end the program, type CTRL+Z.
[1] We call this FAD, short for "functions as designed".
 
Michael.H.Sun
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Susan and Tom,
Thank you very much for the answer.
However, I can not figure it how to do it. Would you give me some instructions step by step. I greatly appreciate you help?
Originally posted by Susan Hoover:
The program is worked properly[1].
You have specified System.in as your input stream. By default, System.in refers to the console, i.e. your keyboard generates the input. If you run your example program and then type some text followed by Return/Enter, the text you typed will be echoed to the screen (where System.out refers by default). To end the program, type CTRL+Z.
[1] We call this FAD, short for "functions as designed".

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!