aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes The FileWriter Class 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 "The FileWriter Class" Watch "The FileWriter Class" New topic
Author

The FileWriter Class

JiaPei Jen
Ranch Hand

Joined: Nov 19, 2000
Posts: 1309
The rule for the FileOutputStream is that if the file specified as an argument of the FileOutputStream constructor does not exist, a file will be created. If the file exists but is a directory rather than a regular file, does not exist but cannot be created, or cannot be opened for any other reason then a FileNotFoundException is thrown.
What about the FileWriter class? I checked that if the file specified as an argument of the FileWriter constructor does not exist, an IOException will be thrown. Is this one of the differences between FileOutputStream and FileWriter?
mohit joshi
Ranch Hand

Joined: Sep 23, 2000
Posts: 243
I am able to create new FileWriter("xyz.txt"); and the file does get created.(the file should be in the same directory, or and existing directory).
JiaPei Jen
Ranch Hand

Joined: Nov 19, 2000
Posts: 1309
Thanks, Mohit. Then when does the FileWriter class throw IOException other than I/O error occurs? I checked the java.sun.com/j2se/1.3/docs/api, and it says that the write() method of the FileWriter class throws IOException if the specified file is not found.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: The FileWriter Class