使用UNIVOCITY-PARSERS创建和读取CSV文件
来源:互联网 发布:拍卖系统源码 编辑:程序博客网 时间:2024/05/17 23:54
import com.univocity.parsers.csv.CsvFormat;import com.univocity.parsers.csv.CsvParser;import com.univocity.parsers.csv.CsvParserSettings;import com.univocity.parsers.csv.CsvWriter;import com.univocity.parsers.csv.CsvWriterSettings;//创建csv文件:public static void createCSVFile(String[] heads, List<Object[]> rows, String outPutPath, String filename) { // CsvWriter (and all other file writers) work with an instance of // java.io.Writer File csvFile = new File(outPutPath + filename + ".csv"); File parent = csvFile.getParentFile(); if (parent != null && !parent.exists()) { parent.mkdirs(); } try { csvFile.createNewFile(); Writer fileWriter = new FileWriter(csvFile); // By default, only values that contain a field separator are enclosed within quotes. // If quotes are part of the value, they are escaped automatically as well. Empty rows are discarded automatically. // Set the field delimiter to ';', the default value is ',' CsvWriterSettings settings = new CsvWriterSettings(); CsvFormat format = settings.getFormat(); format.setDelimiter(';'); CsvWriter writer = new CsvWriter(fileWriter, settings); // Write the record headers of this file writer.writeHeaders(heads); // Write contents and close the given output Writer instance. writer.writeRowsAndClose(rows); } catch (Exception e) { e.printStackTrace(); logger.error(e); } } //读取csv文件:public static List<MyType> ReadCSV(String filePath) throws IOException { List<MyType> eslImports = new ArrayList<MyType>(); File file = new File(filePath); InputStream in = new FileInputStream(file); InputStreamReader reader = new InputStreamReader(in, "UTF-8"); CsvParserSettings settings = new CsvParserSettings(); settings.getFormat().setLineSeparator("\n"); CsvParser parser = new CsvParser(settings); //读取数据到列表 List<String[]> allRows = parser.parseAll(reader); //处理读取到的数据 .....}
0 0
- 使用UNIVOCITY-PARSERS创建和读取CSV文件
- uniVocity-parsers:一款强大的CSV/TSV/定宽文本文件解析库(Java)
- uniVocity-parsers:速度最快功能最全的CSV开发库
- 使用Python读取和写入CSV文件
- 使用Python读取和写入CSV文件
- 使用lua读取csv文件
- CSV文件读取和处理
- Spark创建DataFrame和读取CSV数据文件
- Spark创建DataFrame和读取CSV数据文件
- c++读取csv文件和写入文件
- Silverlight4使用radgridview读取导出CSV文件
- 生成csv文件 可以使用excell读取
- ruby 使用csv读取文件问题
- 使用python pandas读取csv文件数据
- 使用pandas read_table读取csv文件
- Jmeter使用CSV文件读取大量测试数据
- 读取Excel和CSV文件数据
- Java读取和写入CSV文件
- C++ stl队列Queue用法介绍:删除,插入等操作代码举例
- Linux 文件系统的创建与挂载方法
- Bootstrap插件预览
- mongodb安装教程。
- java中hashCode方法与equals方法的用法总结
- 使用UNIVOCITY-PARSERS创建和读取CSV文件
- 第三方APP微信支付Java服务端构建步骤
- 第7章 证据的效力如何
- 写给嵌入式程序员的循环冗余校验(CRC)算法入门引导
- Android中bindService的使用方法
- *leetcode #90 in cpp
- how to use cmake
- CodeForces - 676A Nicholas and Permutation (模拟) 水
- c++ stl容器set成员函数介绍及set集合插入,遍历等用法举例