aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes IO Question from javacaps 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 "IO Question from javacaps" Watch "IO Question from javacaps" New topic
Author

IO Question from javacaps

Amit Punjwani
Ranch Hand

Joined: Jul 10, 2000
Posts: 50
Question from Javacaps mock exam
55. You have an 8-bit file using the character set defined by ISO 8859-8. You are writing an application to display this file in a TextArea. The local encoding is already set to 8859-8. How can you write a chunk of code to read the first line from this file?
You have three variables accessible to you:
myfile is the name of the file you want to read
stream is an InputStream object associated with this file
s is a String object
Select all valid answers.
A)
InputStreamReader reader = new InputStreamReader(stream, "8859-8");
BufferedReader buffer = new BufferedReader(reader);
s = buffer.readLine();
B)
InputStreamReader reader = new InputStreamReader(stream);
BufferedReader buffer = new BufferedReader(reader);
s = buffer.readLine();
C)
InputStreamReader reader = new InputStreamReader(myfile, "8859-8");
BufferedReader buffer = new BufferedReader(reader);
s = buffer.readLine();
D)
InputStreamReader reader = new InputStreamReader(myfile);
BufferedReader buffer = new BufferedReader(reader);
s = buffer.readLine();
E)
FileReader reader = new FileReader(myfile);
BufferedReader buffer = new BufferedReader(reader);
s = buffer.readLine();
Given ans : Only A
But why not
[B] if the local encoding is already set to 8859-8. The rest of the code is same.
and [E] FileReader which is again subclass of InputStreamReader reads with default local encoding
Comments please
Amit
Amit Punjwani
Ranch Hand

Joined: Jul 10, 2000
Posts: 50
Someone please help me with this question
Thanx in adv
Amit
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: IO Question from javacaps
 
Similar Threads
i/o
java io question, conceptual query
Need help viewing text file in text area
About IO!
IO Question