jQuery in Action, 2nd edition*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes i/o Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "i/o" Watch "i/o" New topic
Author

i/o

ashok khetan
Ranch Hand

Joined: Jul 29, 2001
Posts: 153
From java-caps Mock-exam:-
Q55. 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
Is it the right answer?
______________________
FileReader reader = new FileReader(myfile);
BufferedReader buffer = new BufferedReader(reader);
s = buffer.readLine();
______________________
swati bannore
Ranch Hand

Joined: Oct 18, 2000
Posts: 201
Yes, this is the right answer..plus you can use InputStreamReader forthe same purpose.
InputStreamReader input = new InputStreamReader(stream);
BufferedReader buf = new BufferedReader(input);
s = buf.readLine();


Swati Kale
SCJP
SCWCD
ashok khetan
Ranch Hand

Joined: Jul 29, 2001
Posts: 153
hi!
see..the argument is the name of the file in FileInputStream and i think it is not right..it should be either a String containing the name of the file or a File object.so what?
ashok.
swati bannore
Ranch Hand

Joined: Oct 18, 2000
Posts: 201
HI,
Where r u..? InputStreamReader is taking a "stream" argument and NOT the file object......!!
Hope it will clear ur doubts..
Thanx
swati bannore
Ranch Hand

Joined: Oct 18, 2000
Posts: 201
And FileReader do take File object as argument to constructor.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: i/o
 
Similar Threads
java io question, conceptual query
IO Question from javacaps
About IO!
Java I/O
IO Question