This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
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 Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "I/O" Watch "I/O" New topic
Author

I/O

hema janani
Ranch Hand

Joined: May 19, 2000
Posts: 70
1. what is the correct format of reading a line of
String objects ?
a) FileInputStream fis = new
FileInputStream("Filename.txt");
b) DataInputStream dis = new DataInputStream(new
FileInputSTream("FileName.txt"));
c) DataInputStream dis = new DataInputStream(new
FileInputSTream("FileName.txt"), "r");
I think it's a,b
please reply.
Kishan Kumar
Ranch Hand

Joined: Sep 26, 2000
Posts: 130
Janani,
Answer c is no doubt wrong because of its syntax. it holds good
only a RandomAccess file.
Answer a is also wrong because there is no method by which u can
read a line using the FileInputStream. It can only read bytes of
data rather than in terms of Strings or chars or primitives.
Answer b is the correct answer.
The question is which of the following correctly reads a LINE of
String objects.
Hope this helps.
------------------
Regards,
V. Kishan Kumar


Regards,<BR>V. Kishan Kumar
hema janani
Ranch Hand

Joined: May 19, 2000
Posts: 70
thanks Kishan
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
yes ,
the above things are good reasons
answer b is correct
srinivasan.e
George Brown
Ranch Hand

Joined: Sep 26, 2000
Posts: 919
IMHO, none of them would work...
The case of the FileInputStream() method in (b) is incorrect (there's no upper-case T in the method name):
DataInputStream dis = new DataInputStream(new FileInputSTream("FileName.txt"));
Call me Mr Picky Pedant, but the exam does call for exactitude.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: I/O
 
Similar Threads
How can I use StringBuffer in this case...
I / O
Little help with reading files
DataOutputStream
Input/Output(urgent)