java csv 双引号_你知道csv中如何输出英文双引号吗-百度经验

再上一段希望生成上述csv的代码:

package chapter4;

import java.io.File;

import java.io.FileWriter;

import java.io.IOException;

import java.util.ArrayList;

import java.util.List;

/**

* Created by MyWorld on 2016/3/23.

*/

public class CsvWriteWithDoubleQuotation {

public static void main(String[] args) throws IOException {

List source = getResult();

CsvWriteWithDoubleQuotation csvWriter = new CsvWriteWithDoubleQuotation();

csvWriter.write(source);

}

private void write(List source) throws IOException {

File file = new File("resultWithDoubleQuotation.csv");

System.out.println(file.getAbsolutePath());

FileWriter fw = new FileWriter(file);

String title = "id,Name,Desc";

fw.write(title + "\n");

for (Peron peron : source) {

fw.write(String.format("%s,%s,\"%s\"\n", peron.getId(), peron.getName(), peron.getDesc()));

}

fw.flush();

fw.close();

}

private static List getResult() {

List source = new ArrayList();

source.add(new Peron(1, "Tom", "I li kui, nicknamed \"black tornado\""));

source.add(new Peron(2, "Jim", "I'm Jim"));

source.add(new Peron(3, "John", "I'm John,twenty years old."));

return source;

}

}

class Peron {

private final int id;

private final String name;

private final String desc;

public Peron(int id, String name, String desc) {

this.id = id;

this.name = name;

this.desc = desc;

}    public int getId() {

return id;

}    public String getName() {

return name;

}

public String getDesc() {

return desc;

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值