• 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
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

file instance

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi everyone,
1> In the foll. ques
To create a file,you can use an instance of class
a>File
b>randomaccessfile
c>FileOutputStream
d>any of these //ans
e>b and c
but acc. to me it should be a>File as we use an instance of File class to create a file like,
File f=new File("file name");
FileOutputStream fos=new FileOutputStream(f);
RandomAccessFile ras=new RandomAccessFile(f);
2> Can an applet be added to a container?
I think it can't be as it itself is a container
pl.anybody clear my doubt
thanks in advance,
Mamta
 
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1)I think ans should be e) since File class can only be use to manipulate the file system,not to create files.
2)Of course applet can be added a container since container can include containers.
Anyone can correct me?
 
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For question 1, its (d), because if you use
RandomAccessFile with mode "rw" and the file does not exist, a new empty file is created. Similarly for FileOutputStream, if the file does not exist, it is created. So the answer is (d) any of these.
For question 2, The answer is yes, as containers can contain containers.
thanks,
Zulfiqar Raza.

Originally posted by Mamta Jha:
hi everyone,
1> In the foll. ques
To create a file,you can use an instance of class
a>File
b>randomaccessfile
c>FileOutputStream
d>any of these //ans
e>b and c
but acc. to me it should be a>File as we use an instance of File class to create a file like,
File f=new File("file name");
FileOutputStream fos=new FileOutputStream(f);
RandomAccessFile ras=new RandomAccessFile(f);
2> Can an applet be added to a container?
I think it can't be as it itself is a container
pl.anybody clear my doubt
thanks in advance,
Mamta


 
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am of the opinion that answer d) is the correct choice here.
1)You can use an instance of the File class to create a new file if the file passed to the File class constructor does not exist , by means of createNewFile() method.
2)FileOutputStream will also create the file passed to it and start writing to it if the specified file does not exist.
3)For RandomAccessFile , if the mode is 'rw' then the file will be created on the underlying system.
------------------
Come on in !! Drinks are on the house in the Big Moose Saloon !!
 
arch rival
Posts: 2813
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Any of the answers given so far may be correct, but if you write some code to use these classes, you will know for certain what really happens. Javac is a great teacher.
Marcus
 
"Don't believe every tiny ad you see on the internet. But this one is rock solid." - George Washington
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic