• Post Reply Bookmark Topic Watch Topic
  • New Topic

when end of stream is found?

 
nisharma sharma
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello everybody.
please tell me, what a user should entered at run time so that read method of InputStreamReader gets end of stream and return -1.I made the object like this..
InputStreamReader isr=new InputStreamReader(System.in);
Thanks .
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ctrl-Z is the keyboard input for EOF. The user has to hit Enter to get anything into your reader. So Ctrl-Z Enter ended this program with a -1.

Interesting:
"Ctrl-Z Enter" -> -1
"a Enter" -> 97 13 10
"a Ctrl-Z Enter" -> 97 26 13 10
26 is Escape, no? Wonder why that happened.
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24213
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Note that ^Z is only going to be EOF on Win32. On UNIX it's ^D.
 
nisharma sharma
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you very much Stan and Freidman to response me, but still i am facing problem.As soon as I press ctrl+z,it throw me out from application and a command prompt is shown.
input ctrl+z -> throw me outside the application before pressing the enter
while it should wait for pressing enter.And after pressing it should display dddddddddddddd.
I wrote this code....
import java.io.*;
class io{
public static void main(String []args){
try{
int i=0,j=0;
InputStreamReader in=new InputStreamReader(System.in);
while((i=in.read())!=(-1)){
System.out.println("i="+i);
}
System.out.println("ddddddddddddd");
}catch(IOException e){System.out.println(e.getMessage());}
}
}
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you using Unix (e.g. Linux)? Did you read Ernest's answer?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!