簡體   English   中英

FileOutputStream追加替代

[英]FileOutputStream append alternative

我有這種方法:

public static void write(String s, File f, String charset, boolean append) throws IOException {
    final FileOutputStream fileStream = new FileOutputStream(f, append);
    final OutputStreamWriter out = charset == null ? new OutputStreamWriter(fileStream) : new OutputStreamWriter(fileStream, charset);
    final BufferedWriter w = new BufferedWriter(out);
    try {
        w.write(s);
    } finally {
        w.close();
    }
}

但是我無法在應用程序中的任何地方使用FileOuputStream,我需要對輸出流進行相同的寫入。 我如何才能更改此方法,以使其在不使用FileOuputStream的情況下也能做到相同,並且append(合並兩個文件)的目的是什么? 我在Google App Engine上使用了此功能,因此Google App Engine的Java運行時環境不支持在文件系統上進行寫入,並且某些類已列入黑名單。

由於AppEngine通常不支持文件系統寫入 ,因此更改代碼不太可能對您有所幫助。

您可以將其更改為使用URLFileChannel但這無濟於事。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM