I am trying to read the contents of a file using FileReader.
Here I am using a read() method to read it.The read() reads character and returns integer in range 0 to 65535.
So I have created int ch,but System.out.println(ch); works and prints the characters without casting it to character.I am confused at this point
System.out.println does a "toString()" on its argument. You can check the source code of the relevant classes (Integer in this case) to see what's involved in that.
Ah, you're right, there is a PrintStream.println(int). So steeped in Java 5 autoboxing by now that I assumed that println(Object) would be called. Both probably do pretty much the same thing, though.
It is, though, fairly unusual to read text data from a file using a FileReader by itself. You can use the FileReader in combination with other classes that make things easier, e.g. BufferedReader:
Well, Sam, I don't know what to tell you. That's definitely not true; your program will print the Unicode character value for each character as a decimal integer on a separate line -- i.e., for my system, it'll print '48' for the character '0'. Are you sure the code you're running is the code you're looking at? Maybe you got different versions of your program mixed up?