This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Files 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 "Files" Watch "Files" New topic



Joined: May 30, 2000
Posts: 10
I have a question on Files.
Does createNewFile() mtd of File creates a file on local system?
Carl Trusiak

Joined: Jun 13, 2000
Posts: 3340
Originally posted by boskey:
I have a question on Files.
Does createNewFile() mtd of File creates a file on local system?

From the api documentation
public boolean createNewFile()
throws IOException
Atomically creates a new, empty file named by this abstract pathname if and only if a file with this name does not yet exist. The check for the existence of the file and the creation of the file if it does not exist are a single operation that is atomic with respect to all other filesystem activities that might affect the file. This method, in combination with the deleteOnExit() method, can therefore serve as the basis for a simple but reliable cooperative file-locking protocol.
true if the named file does not exist and was successfully created; false if the named file already exists
IOException - If an I/O error occurred
SecurityException - If a security manager exists and its SecurityManager.checkWrite( method denies write access to the file

I Hope This Helps
Carl Trusiak, SCJP2, SCWCD
I agree. Here's the link:
subject: Files
It's not a secret anymore!