首页 > Web开发 > 详细

apache common之CSV文件操作

时间:2015-03-19 02:12:31      阅读:363      评论:0      收藏:0      [点我收藏+]

依赖jar:

<dependency>
	<groupId>org.apache.commons</groupId>
	<artifactId>commons-csv</artifactId>
	<version>1.0</version>
</dependency>

写操作:

List<String[]> data = new ArrayList<String[]>();
data.add(new String[] { "A", "B", "C" });
data.add(new String[] { "1", "2", "3" });
data.add(new String[] { "A1", "B2", "C3" });
FileWriter fw = new FileWriter(new File("c:/linkrmb.com.csv"));
final CSVPrinter printer = CSVFormat.EXCEL.print(fw);
printer.printRecords(data);
printer.flush();
printer.close();

读操作:

String path = "c:/linkrmb.com.csv";
InputStream inputStream = new FileInputStream(path);
InputStreamReader isr = new InputStreamReader(inputStream);
Iterable<CSVRecord> records = CSVFormat.EXCEL.parse(isr);
for (CSVRecord record : records) {
	for (String string : record) {
		System.out.print(string);
		System.out.print("-");

	}
	System.out.println();
	System.out.println("*****************");
}

?

apache common之CSV文件操作

原文:http://snv.iteye.com/blog/2193670

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!