wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes FileWriter and FileOutputStream:confused: Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "FileWriter and FileOutputStream:confused:" Watch "FileWriter and FileOutputStream:confused:" New topic
Author

FileWriter and FileOutputStream:confused:

Mike Kelly
Ranch Hand

Joined: Jul 18, 2001
Posts: 78
I'm a little fuzzy on a concept. I thought Java would not let you to create a new file unless it did not already exist. But know I understand that FileWriter and FileOutputStream constructors replace the original files when constructing with existing file name. I thought the former were for security principles.
Ivor Horton
Author
Ranch Hand

Joined: Mar 22, 2002
Posts: 67
No, you can create new files and update or overwrite existing files in Java. In an applet you have no access to files other than those in the directory that contains the applet (for icons etc). You can also delete files and directories using the delete() method for a File object.
If you don't want to overwrite an existing file in a Java application, be sure to use the FileOutputStream constructor with two arguments with the second argument (append) specified as true.


Ivor Horton<br />Author of the Beginning Java Series including the new <a href="http://www.amazon.com/exec/obidos/ASIN/1861005695/ref=ase_electricporkchop" target="_blank" rel="nofollow">Beginning Java 2 SDK 1.4 Edition</a>
Mike Kelly
Ranch Hand

Joined: Jul 18, 2001
Posts: 78
Well Thanks Ivor, Thanks for clearing that up. I't was just something erroneous I had in my head.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: FileWriter and FileOutputStream:confused:
 
Similar Threads
FileWriter vs BufferedWriter
Is there a I/O method to convert text to html?
FileWriter.write(String str)
Nikos Question
Current Working Directory?