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 Why FileOutputStream cann't create an empty file in following statement 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 "Why FileOutputStream cann Watch "Why FileOutputStream cann New topic
Author

Why FileOutputStream cann't create an empty file in following statement

Hades Pan
Ranch Hand

Joined: Nov 25, 2001
Posts: 106
Which of the following will create an empty file. select 2
FileInputStream
RandomAccessFile is constructed as "rw".
FileOutputStream.
Uma Viswanathan
Ranch Hand

Joined: Jun 14, 2001
Posts: 126
FileInputStream: (Low level input stream)
You can only read

RandomAccessFile is constructed as "rw"
If you open with RAF, if the file does not exist, it will create a new file.
FileOutputStream: (low level output stream)
There are 4 constructors in this class. One takes the FileDescriptor object (which represents an already existing connection to an actual file). This one will not create a new file.
Remaining three constructors [one takes the file name as String, one takes the file name as String with another boolean parameter (whether to append or not), third one takes the file name as File] will create a new empty file, if does not exist. If a file can not be created, then all the three will throw FileNotFoundException.
All the four constructors will throw SecurityException when the call to checkWrite() denies permission to write
So, the answers are RAF and FileOutputStream.
Uma
Hades Pan
Ranch Hand

Joined: Nov 25, 2001
Posts: 106
So detailedly explanans of UMA is!!
Thanks a lot~~~~!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Why FileOutputStream cann't create an empty file in following statement