File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes i/o streams Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "i/o streams" Watch "i/o streams" New topic
Author

i/o streams

ashok khetan
Ranch Hand

Joined: Jul 29, 2001
Posts: 153
hi,
what will be right answer for the following question?(from boone's mock-exam).
File f = new File("hello.test");
FileOutputStream out = new FileOutputStream(f);

Select the one right answer.
a) Create a new file named "hello.test" if it does not yet exist. It also opens the file so you can write to it and read from it.
b) Create a new file named "hello.test" if it does not yet exist. The file is not opened.
c) Open a file named "hello.test" so that you can write to it and read from it, but does not create the file if it does not yet exist.
d) Open a file named "hello.test" so that you can write to it but cannot read from it.
e) Create an object that you can now use to create and open the file named "hello.test," and write to and read from the file.
Roopa Bagur
Ranch Hand

Joined: Nov 03, 2000
Posts: 267
I think the answer is b
Originally posted by ashok khetan:
hi,
what will be right answer for the following question?(from boone's mock-exam).
File f = new File("hello.test");
FileOutputStream out = new FileOutputStream(f);

Select the one right answer.
a) Create a new file named "hello.test" if it does not yet exist. It also opens the file so you can write to it and read from it.
b) Create a new file named "hello.test" if it does not yet exist. The file is not opened.
c) Open a file named "hello.test" so that you can write to it and read from it, but does not create the file if it does not yet exist.
d) Open a file named "hello.test" so that you can write to it but cannot read from it.
e) Create an object that you can now use to create and open the file named "hello.test," and write to and read from the file.

Mini Pilla
Ranch Hand

Joined: Jul 15, 2001
Posts: 112
I think the answer is d.
Actually u can do a search of these type of questions which are ambigious.
Thanx
Rajani

[This message has been edited by Rajani Katta (edited August 31, 2001).]
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
I think the answer is b
swati bannore
Ranch Hand

Joined: Oct 18, 2000
Posts: 201
HI,
Even I had posted this question recently.I think,option d is correct.When we create a FileOutputStream Object,a file object is created for writing to the file or if it exists,it is opened for writing.
It thorws exception in following cases-
If the file exists but is a directory rather than a regular file, does not exist but cannot be created, or cannot be opened for any other reason then a FileNotFoundException is thrown.


Swati Kale
SCJP
SCWCD
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9047
    
  10
File f = new File("hello.test")
does not create a file.
File (from the Java Tutorial) "represents a file on the native file system. You can create a File object for a file on the native file system."
Therefore 'b' cannot be the correct answer.
[This message has been edited by Marilyn deQueiroz (edited September 01, 2001).]


JavaBeginnersFaq
"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
Abdul Latif
Ranch Hand

Joined: Jul 18, 2001
Posts: 89
the answre is d
Because a FileOutputStream creates a file if the file object does not represent a file on the host macnine.
since FileOutputStream is used for writing to files it can only wite & cant read
hope it helps
Desai Sandeep
Ranch Hand

Joined: Apr 02, 2001
Posts: 1157
Hi Ashok,
The API doc says :


public FileOutputStream(File file) throws FileNotFoundException
Creates a file output stream to write to the file represented by the specified File object.



The file is created using java.io.FileOuptputStream.But is the file opened?I think the answer is YES, otherwise you cannot write into it.Hence, D is the correct answer.
B is incorrect, since the API DOC also mentions that the parameter to the Constructor, is the File to be opened for writing.
Hope this helps,
Sandeep
SCJP2, OCSD(Oracle JDeveloper), OCED(Oracle Internet Platform)

<b>Sandeep</b> <br /> <br /><b>Sun Certified Programmer for Java 2 Platform</b><br /> <br /><b>Oracle Certified Solution Developer - JDeveloper</b><br /><b>-- Oracle JDeveloper Rel. 3.0 - Develop Database Applications with Java </b><br /><b>-- Object-Oriented Analysis and Design with UML</b><br /> <br /><b>Oracle Certified Enterprise Developer - Oracle Internet Platform</b><br /><b>-- Enterprise Connectivity with J2EE </b><br /><b>-- Enterprise Development on the Oracle Internet Platform </b>
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: i/o streams