依赖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文件操作的全部内容,更多相关apache内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复