• 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
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

I/O AGAIN

 
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Import java.io.*;
class Happy {
public static void main(String args[]) {
try {
File f = new File(Test.txt);
OutputStream o=new FileOutputStream(f);
}
catch(IOException e) { }
}
}
What happens when this code compiles and run?
a) Compilation error.
b) The code compiles and runs successfully but no file is created.
c) A file with zero length is created.
d) The code compiles but there will be a RuntimeException because there
is no matching constructor for the FileInputStream.

[This message has been edited by Hades Pan (edited December 06, 2001).]
 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
a - compilation error.
 
Ranch Hand
Posts: 1492
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Hades,
Assuming you made some typing mistakes:
Import should be import, and
Quotes are required around the Test.txt parameter to File.
I remember this question from some mock. The correct answer, given the above corrections, is that an empty file will be created.
The new File call will not create a file on the existing OS, but the OutputStream will.
Regards,
Manfred.
 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
it results in compile time error caz
Test.txt should be wrapped into " "
second thing is that though OutputStream is parent of FileOutputStream and implicit conversion is valid. but we must remember that OutputStream is an abstract class so it can not be instantiated.
rgds
vishal
 
Ranch Hand
Posts: 464
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ans will be C..
OutputStream though it is abstract still
OutputStream o = new FileOutputStream(new File("java.txt"));
will work
ragu
 
Hades Pan
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you very one!
 
The only thing that kept the leeches off of me was this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic