通过opencsv在文件结尾处写入

通过opencsv在文件结尾处写入

本文介绍了通过opencsv在文件结尾处写入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用并要写入 .csv code>文件通过多个季节。
不过每次我开始一个新的旧的文件被擦除。
我可以以某种方式将的行为更改为 https://docs.oracle.com/javase/7/docs/api/java/io/FileWriter.html =nofollow noreferrer> FileWriter ,而不是以附加到文件末尾。



此代码使其工作:

  mFileWriter = new FileWriter(file_path,true); 
mCsvWriter = new CSVWriter(mFileWriter);


I'm using opencsv and want to write to a .csv file through multiple seasons.However every time I start a new CSVWriter the old file gets erased.Can I somehow change the behavior of the CSVWriter to write at the end of the file instead of replacing the file?

解决方案

It seems that there's an option in the FileWriter instead of the CSVWriter to append at the end of the file.

This code makes it work:

mFileWriter = new FileWriter(file_path, true);
mCsvWriter = new CSVWriter(mFileWriter);

这篇关于通过opencsv在文件结尾处写入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 18:10