aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Doubt Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Doubt " Watch "Doubt " New topic
Author

Doubt

Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Hi, please look at the code
Which of the following are true statements?
1) I/O in Java can only be performed using the Listener classes
2) The RandomAccessFile class allows you to move directly to any point a file.
3) The creation of a named instance of the File class creates a matching file in the underlying operating system only when the close method is called.
4) The characteristics of an instance of the File class such as the directory separator, depend on the current underlying operating system
Answers:
2,4
The below is explanantion for answer not being 3
The File class can be considered to represent information about a file rather than a real file object. You can create a file in the underlying operating system by passing an instance of a file to a stream such as FileOutputStream.
//The file will be created when you call the close method of the stream.
I cant understand the statement //...
Even if the close() method is not invoked also, the file
is created with data.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12675
    
    5
You are correct - the file will be created when you open the FileOutputStream - close() just flushes and closes it.
Note that Java 1.2 added some methods to java.io.File which can actually create a file. Before that the File class was more limited.
Bill

Java Resources at www.wbrogden.com
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Originally posted by William Brogden:
You are correct - the file will be created when you open the FileOutputStream - close() just flushes and closes it.
Note that Java 1.2 added some methods to java.io.File which can actually create a file. Before that the File class was more limited.
Bill

Thanks Bill.I know that only FileOutputStream and RandomAccessFile will create new file.Can u give me the
list which would create a new file including the additions
in java1.2.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Doubt
 
Similar Threads
Strange type of questions ...
Reg. close method
Doubt
FileWriter vs BufferedWriter
FileWriter.write(String str)