This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Soft Skills: The software developer's life manual and have John Sonmez on-line!
See this thread for details.
Win a copy of Soft Skills: The software developer's life manual this week in the Jobs Discussion forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

read() of FileReader

 
Deepak Bobal
Ranch Hand
Posts: 96
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

output
File is written
Data is 84
104-- T
105-- h
115-- i
32-- s
105--
115-- i
32-- s
84--
101-- T
120-- e
116-- x
32-- t
102--
105-- f
108-- i
101-- l
-1-- e


read() of FileReader class , returns int value but at line 3 it seems that it returns array of integers as i apply while loop on it.I dont understand output "Data is 84 " from line 2 . how this 84 is coming.

Thank You
 
Ulf Dittmer
Rancher
Pie
Posts: 42966
73
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
read() returns an int, as its javadocs specify. Line "2" prints that integer, and the javadocs explain what that number means.

You are not applying the while loop to what a single read() returns, you are repeatedly calling read() and it returns a different number each time.

The real problem that I think is hindering your understanding is that lines 21 and 22 are switched around - the output does not line up the characters with their respective numerical values correctly.


} catch (IOException i) {
}

You should never ignore IO exceptions; at the very least write a message to the console so that you'll know if something went wrong.

Also, you've been around the ranch long enough to know that you should UseCodeTags when posting code. It's unnecessarily hard to read it otherwise, making it less likely that people will bother to do so.
 
Jim Jonides
Ranch Hand
Posts: 42
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Totally agree with Ulf. It will become obvious if you change the file reading code to following:

 
Deepak Bobal
Ranch Hand
Posts: 96
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Ulf.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic