Win a copy of Spring Boot in Practice this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

when end of stream is found?

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 .
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
author and iconoclast
Posts: 24204
44
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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());}
}
}
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are you using Unix (e.g. Linux)? Did you read Ernest's answer?
 
reply
    Bookmark Topic Watch Topic
  • New Topic