1

This code appends to an already created Excel file:

FileOutputStream fileOut = new FileOutputStream("c:\\Decrypted.xls");

What can we add / modify so that Decrypted.xls should be created if not already created and appended if already created?

2
  • There isn't anything specific to Excel files. That could just as well be edited out. Commented Nov 25, 2009 at 19:05
  • 1
    I wonder what the purpose of this is? Somehow I doubt that the result will be a working, bigger Excel file with more data in it. Commented Nov 25, 2009 at 19:11

3 Answers 3

1

You want the FileOutputStream(File file, boolean append) constructor for switching on whether you truncate or append.

Sign up to request clarification or add additional context in comments.

Comments

0

According to the Javadocs for the String-accepting constructor of FileOutputStream, rover12, if the file doesn't already exist then it's created. Are you not seeing this behavior?

(And as others have mentioned, be sure to use the constructor that takes the second boolean argument so you can specify that you want to append the file if it already exists...)

1 Comment

no i am not seeing this behaviour .. if i delete the already existing Decrypted.xls i get an error compliling that says .. file does not exist
0

Use the constructor:

FileOutputStream fileOut = new FileOutputStream("c:\\Decrypted.xls", true);

to append to an existing file, if it doesn't exist. Your example will overwrite the existing one.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.