文件追加模式

在处理分批次写入文件时,不使用追加模式可能导致文件损坏。Java中,通过设置FileInputStream构造函数的append参数为true,可以实现追加模式,避免覆盖原有内容。理解这一参数对于防止文件数据丢失至关重要。
摘要由CSDN通过智能技术生成

           今天踩了一个坑,在分批次写入文件时,损坏了文件,后来经过排查发现,需要使用追加模式来写文件,否则每次都是从头开始写。这个就是FileInputStream的构造函数里面的一个参数决定的。

          

/**
     * Creates a file output stream to write to the file represented by
     * the specified <code>File</code> object. If the second argument is
     * <code>true</code>, then bytes will be written to the end of the file
     * rather than the beginning. A new <code>FileDescriptor</code> object is
     * created to represent this file connection.
     * <p>
     * First, if there is a security manager, its <code>checkWrite</code>
     * method is called with the path represented by the <code>file</code>
     * argument as its argument.
     * <p>
     * If the file exists but is a directory rather than a regular file, does
     * not exist but cannot be created, or cannot be opened for any other
     * reason then a <code>FileNotF
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值