2

ローリング ファイルがログにどのように実装されているか、常に興味があります。

ファイルサイズを超えないようにするために、どの言語でもファイル書き込みクラスの作成を開始するにはどうすればよいでしょうか。

私が考えることができる唯一の可能な解決策はこれです:

write method:
    size = file size + size of string to write
    if(size > limit)
        close the file writer
        open file reader
        read the file
        close file reader
        open file writer (clears the whole file)
        remove the size from the beginning to accommodate for new string to write
        write the new truncated string
    write the string we received

これはひどい実装のように思えますが、これ以上良いものは思いつきません。

具体的には、Java での解決策を知りたいです。

編集: 最初からサイズを削除すると、20 バイトの文字列 (制限) があるとしましょう。別の 3 バイト文字列を書きたいので、最初から 3 バイトを削除し、最後に 17 バイトが残ります。新しい文字列を追加すると、20バイトになります。

4

1 に答える 1