This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
Suren, Here is why answer E) is correct. I quote from "Java in a Nutshell" (2nd edition), p. 411:
"FileReader is a convenience subclass of InputStreamReader..."
"The FileReader constructor internally creates a FileInputStream to read bytes from the specified file, and uses the functionality of its superclass, InputStreamReader, to convert those bytes from characters in the local encoding to Unicode characters using Java."
"If you want to read Unicode character from a file that uses some encoding other that the default encoding for the locale, you must explicitly create your own InputStreamReader to perform the byte-to-character conversion". Of course you can always read the freely-available API. Hope this helps, Panagiotis. --------------------------------- E) FileReader reader = new FileReader(myfile); BufferedReader buffer = new BufferedReader(reader); s = buffer.readLine();
Hi I chanced upon this post while studying IO(one of the most confusing topics with a zillion things to grasp ). I have a question here. None of the correct options mentioned in the post use a try catch block while calling the readLine method of the BufferedReader class and all of them would give a compilation error. IMHO, the question should be appropriately worded- ie it should mention explicitly that the method calling the correct piece of code throws IOException OR The code fragments should be revised to trap the exception. Does anyone agree/disagree ? Thanks, Sajida