• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

FileWriter and FileOutputStream:confused:

 
Mike Kelly
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Mike Kelly
Ranch Hand
Posts: 78
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well Thanks Ivor, Thanks for clearing that up. I't was just something erroneous I had in my head.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic