通过opencsv在文件结尾处写入 [英] Writing at the end of a file via opencsv

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

问题描述

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



此代码使其工作:

  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在文件结尾处写入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆