• 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:
  • Campbell Ritchie
  • Paul Clapham
  • Bear Bibeault
  • Liutauras Vilda
  • Devaka Cooray
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • Henry Wong
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Tim Holloway
Bartenders:
  • salvin francis
  • Frits Walraven
  • Piet Souris

The FileWriter Class

 
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.
 
And then the flying monkeys attacked. My only defense was this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!