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?
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?
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...)
You want the FileOutputStream(File file, boolean append)
constructor for switching on whether you truncate or append.
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.