aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes file instance Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "file instance" Watch "file instance" New topic
Author

file instance

Mamta Jha
Greenhorn

Joined: Oct 18, 2000
Posts: 8
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
Bin Zhao
Ranch Hand

Joined: Oct 04, 2000
Posts: 73
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?
zulfiqar raza
Ranch Hand

Joined: Oct 18, 2000
Posts: 81
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

Udayan Naik
Ranch Hand

Joined: Oct 18, 2000
Posts: 135
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 !!


Udayan Naik<BR>Sun Certified Programmer for the Java 2 Platform
Marcus Green
arch rival
Rancher

Joined: Sep 14, 1999
Posts: 2813
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


SCWCD: Online Course, 50,000+ words and 200+ questions
http://www.examulator.com/moodle/course/view.php?id=5&topic=all
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: file instance