Limit file size while writing in java

后端 未结 4 695
情话喂你
情话喂你 2021-01-06 06:10

I need to limit the file size to 1 GB while writing preferably using BufferedWriter.

Is it possible using BufferedWriter or I have to use

4条回答
  •  孤城傲影
    2021-01-06 06:15

    IIUC, there are various ways to do it.

    1. Keep writing data in chucks and flushing it and keep checking the file size after every flush.
    2. Use log4j (or some logging framework) which can let us rollover to new file after certain size or time or some other trigger point.
    3. While BufferedReader is great, there are some new APIs in java which could make it faster. Fastest way to write huge data in text file Java

提交回复
热议问题