Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

read( ) method  RSS feed

 
Urooj Ajmal
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When i use while((inst.read() != -1) condition to read from a stream, it reads skipping alternate characters. help!
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What happens inside your loop, another inst.read() ?
 
Jerel Wakayama
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When i use while((inst.read() != -1) condition to read from a stream, it reads skipping alternate characters. help!
Example:
int i = 0;
while((i = inst.read()) != -1) {
//do stuff
}
Counter Example:
while(inst.read() != -1) {
//read() already called once above.
int i = inst.read();
}
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!