The FileReader class is used to perform I/O on characters.
I try to read a file that is placed in directory and passed as argument in the FileReader constructor. The file contains some character values like abcd.
When i try to read from the FileReader with read method, it returns values in ASCII, whereas FileReader is used for characters. Why does this happen? If unicde concept is taken, then when we read characters from a file then it must convert in characters. But this does not happen.
Data in file “xyz.txt” is “abcd”.
Code:
File h=new File("d:/xyz.txt");
FileReader j=new FileReader(l);
for(int i=0;i<h.length;i++)
{
System.out.println(j.read());
}
I want it to print “abcd”. Instead it prints ASCII values, why?
Because the contract of
Readersays it should. You could useread(char[] buf)to read characters directly.