• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

The FileWriter Class  RSS feed

 
Ranch Hand
Posts: 1309
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Ranch Hand
Posts: 243
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1309
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!