Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

i/o streams

 
Ranch Hand
Posts: 153
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 267
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.


 
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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).]
 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think the answer is b
 
Ranch Hand
Posts: 201
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

 
Sheriff
Posts: 9109
12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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).]
 
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 1157
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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)
 
It's exactly the same and completely different as this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic