【发布时间】:2016-09-29 03:41:59
【问题描述】:
我在 byte[] 中得到一个文件,该文件在引号中有逗号分隔值,我想使用 OpenCSV 将其保存为 CSV。我是using this 以CSV格式保存。
以下是我将 byte[] 转换为数组然后将其存储在文件中的代码
byte[] bytes = myByteStream.getFile();
String decoded = new String(bytes, "UTF-8");
//String lines[] = decoded.split("\\r?\\n");
FileOutputStream fos = new FileOutputStream("/home/myPC/Desktop/test.csv");
OutputStreamWriter osw = new OutputStreamWriter(fos, "UTF-8");
CSVWriter writer = new CSVWriter(osw);
String[] row = {decoded};
writer.writeNext(row);
writer.close();
osw.close();
但是上面的代码在周围添加了额外的引号,并且还将所有行合并为一行。
关于如何正确执行此操作的任何帮助?
【问题讨论】:
-
字节数组中的行是否被换行符分割?