문제

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top