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?
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).
posted 17 years ago
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.
No prison can hold Chairface Chippendale. And on a totally different topic ... my stuff:
Thread Boost - a very different sort of advertising