File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes I/O and Streams and the fly likes why does actual byte value returned by read() method differs from the value it assigns Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "why does actual byte value returned by read() method differs from the value it assigns " Watch "why does actual byte value returned by read() method differs from the value it assigns " New topic
Author

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

Manu Ajay
Greenhorn

Joined: Feb 09, 2014
Posts: 2
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
Ranch Hand

Joined: Aug 27, 2012
Posts: 960
    
  10

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

Joined: Aug 07, 2007
Posts: 1939
    
  28
And Welcome to the Ranch
Manu Ajay
Greenhorn

Joined: Feb 09, 2014
Posts: 2
tnx a lot .....Richard Tookey and Tony Docherty
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: why does actual byte value returned by read() method differs from the value it assigns
 
Similar Threads
Java IO Doubt
how to read lines from a file
FileNotFoundException
incomparable types: boolean and null
Out Of Memory Exception