• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

why does actual byte value returned by read() method differs from the value it assigns

 
Manu Ajay
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi every one..Iam just learning io stuff and i have a doubt

i have a file sample.txt that says "java rocks".

I try to read it with the help of my program


output
97 106
97 118
114 32
99 111
115 107
I have noticed that f.read() and x are different .......this is slightly confusing.....please explain
 
Richard Tookey
Bartender
Posts: 1166
17
Java Linux Netbeans IDE
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Each time you use f.read() it read one byte from the file. You do one read in the 'while' argument and a second in the 'println' argument so you read two characters.
 
Tony Docherty
Bartender
Posts: 2971
59
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And Welcome to the Ranch
 
Manu Ajay
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
tnx a lot .....Richard Tookey and Tony Docherty
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic