• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Hades Pan
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Which of the following will create an empty file. select 2
FileInputStream
RandomAccessFile is constructed as "rw".
FileOutputStream.
 
Uma Viswanathan
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 106
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So detailedly explanans of UMA is!!
Thanks a lot~~~~!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic