Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

i/o

 
ashok khetan
Ranch Hand
Posts: 153
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 201
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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();
 
ashok khetan
Ranch Hand
Posts: 153
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 201
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 201
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And FileReader do take File object as argument to constructor.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic