2009-11-25 122 views
1

此代码追加到已创建的Excel文件:爪哇 - 追加到Excel文件FileOutputStream中

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

我们能添加/修改,所以如果尚未创建和附加的,如果已经是Decrypted.xls应创建产生的?

+0

没有任何特定的Excel文件。那也可以编辑出来。 – uckelman 2009-11-25 19:05:21

+1

我不知道这是什么目的?不知何故,我怀疑结果将会是一个工作的,更大的Excel文件,其中包含更多数据。 – 2009-11-25 19:11:44

回答

0

根据the Javadocs for the String-accepting constructor of FileOutputStream,rover12,如果该文件尚不存在,则创建该文件。你没有看到这种行为?

(正如其他人所提到的,一定要使用the constructor that takes the second boolean argument以便您可以指定要追加文件,如果它已经存在...)

+0

不,我没有看到这种行为..如果我删除已经存在的Decrypted.xls我得到一个错误compliling说..文件不存在 – rover12 2009-11-25 19:00:33

+0

不,你是对的..它确实得到创建..对不起 – rover12 2009-11-25 19:01:29

1

你想要FileOutputStream(File file, boolean append)构造函数您是否截断开关或追加。

0

使用构造函数:

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

追加到现有的文件,如果它不存在。你的例子将覆盖现有的例子。