wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Why this output in this I/O program? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Why this output in this I/O program?" Watch "Why this output in this I/O program?" New topic
Author

Why this output in this I/O program?

John-Philippe Verger
Greenhorn

Joined: Feb 18, 2008
Posts: 25
Hi all,

I 've written this program :



In my file scjp.txt , I have typed the number 127 (it's all the content of the file scjp.txt).
When I run the program,I have this output :

49
50
55


I don't understand why I have this output. Please, why this output?


Thanks in advance for your answers.

Ankur kothari
Ranch Hand

Joined: Sep 06, 2009
Posts: 531
dude its because you are printing the int value of the characters 1,2, and 7 which are 49,50and 55
Ankur kothari
Ranch Hand

Joined: Sep 06, 2009
Posts: 531
if c was a character you would have got 127..but c here is a char
Ankur kothari
Ranch Hand

Joined: Sep 06, 2009
Posts: 531
to be precise it had to be an array of char like char c[]..
rohan yadav
Ranch Hand

Joined: Oct 13, 2009
Posts: 156
I think you should try this :


cast c to char will solve your problem


Sage of The Monstrous Toad of Mount Myoboku
John-Philippe Verger
Greenhorn

Joined: Feb 18, 2008
Posts: 25
Thanks you very much Ankur Khotari and Rohan Yadav .
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Why this output in this I/O program?
 
Similar Threads
Printing from a file
Image transfer through sockets
Uploading xls files with JSF
property file
How to use Mark and reset for inputstream ?