View Single Post
Old 04-26-2012, 03:09 AM   PM User | #8
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,639
Thanks: 4
Thanked 2,448 Times in 2,417 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
The try block won't cause the overwrite. Its the print that's doing that. Close shouldn't throw an error in the PrintWriter; only the constructor is mandated to do that.
Move all file handling into a try block. Use only a member to declare the path to it; File() may throw an error as well. Switch it to the FileWriter class as this makes appending easier:
PHP Code:
BufferedWriter writer null;
try
{
    
File myFile = new File(FILEPATH);
    
// here you can force a new file creation if myFile.exists is false.
    
FiileWriter fp = new FileWriter(myFiletrue);
    
writer = new BufferedWriter(fp);
    
writer.write("Appended data");
    
writer.newline();
}
catch (
Exception ex)
{
    
// split up as you see fit.
}
finally
{
    try
    {
        
writer.close();
    }
    catch (
Exception ex)
    {
    }

Try that.
Fou-Lu is offline   Reply With Quote