全栈工程师开发手册 (作者:栾鹏)

java教程全解

java将数据写入csv文件,从csv文件中读取数据

测试代码

   public static void main(String[] arges){//自定义数组ArrayList<ArrayList<String>> alldata=new ArrayList<ArrayList<String>>();alldata.add(new ArrayList<String>(Arrays.asList("1","11","111")));  //添加一行alldata.add(new ArrayList<String>(Arrays.asList("2","22","222")));  //添加一行alldata.add(new ArrayList<String>(Arrays.asList("3","33","333")));  //添加一行//保存成csv文件Array2CSV(alldata,"test.csv");//读取csv文件ArrayList<ArrayList<String>> alldata1=CSV2Array("test.csv");//遍历数组for (ArrayList<String> arrayList : alldata1) {for (String string : arrayList) {System.out.println(string);}}}

将数据写入csv文件

//导出到csv文件public static void Array2CSV(ArrayList<ArrayList<String>> data, String path){try {BufferedWriter out =new BufferedWriter(new OutputStreamWriter(new FileOutputStream(path),"UTF-8"));           for (int i = 0; i < data.size(); i++){ArrayList<String> onerow=data.get(i);for (int j = 0; j < onerow.size(); j++){out.write(DelQuota(onerow.get(j)));out.write(",");}out.newLine();}out.flush();out.close();} catch (Exception e) {e.printStackTrace();}}public static String DelQuota(String str){String result = str;String[] strQuota = { "~", "!", "@", "#", "$", "%", "^", "&", "*", "(", ")", "`", ";", "'", ",", ".", "/", ":", "/,", "<", ">", "?" };for (int i = 0; i < strQuota.length; i++){if (result.indexOf(strQuota[i]) > -1)result = result.replace(strQuota[i], "");}return result;}

从csv文件中读取数据

 public static ArrayList<ArrayList<String>> CSV2Array(String path){try {BufferedReader in =new BufferedReader(new InputStreamReader(new FileInputStream(path),"UTF-8"));ArrayList<ArrayList<String>> alldata=new ArrayList<ArrayList<String>>();String line;String[] onerow;while ((line=in.readLine())!=null) {onerow = line.split(",");  //默认分割符为逗号,可以不使用逗号List<String> onerowlist = Arrays.asList(onerow);ArrayList<String> onerowaArrayList = new ArrayList<String>(onerowlist);alldata.add(onerowaArrayList);}in.close();return alldata;} catch (Exception e) {return null;}}

java将数据写入csv文件,从csv文件中读取数据相关推荐

  1. matlab读Excel表格数据画图,matlab读Excel表格数据画图-matlab如何从excel表格中读取数据?...

    如何将excel表格中大量数据导入matlab中并作图 1.打开matlab,点击主页下面的数据导入,你可以导入excel数据,这里导入你自己命名的huitushuju文件. 2.单击"打开 ...

  2. ffmpeg 从内存中读取数据(或将数据输出到内存)

    更新记录(2014.7.24): 1.为了使本文更通俗易懂,更新了部分内容,将例子改为从内存中打开. 2.增加了将数据输出到内存的方法. 从内存中读取数据 ffmpeg一般情况下支持打开一个本地文件, ...

  3. Flink使用KafkaSource从Kafka消息队列中读取数据

    Flink使用KafkaSource从Kafka消息队列中读取数据 使用KafkaSource从Kafka消息队列中读取数据 1.KafkaSource创建的DataStream是一个并行的DataS ...

  4. R语言:从 csv 文件中读取数据,然后将数据写入 csv 文件

    在 R 中,我们可以从存储在 R 环境外部的文件读取数据.我们还可以将数据写入将由操作系统存储和访问的文件中.R可以读取和写入各种文件格式,如csv,excel,xml等. 在本章中,我们将学习从 c ...

  5. POI:从Excel文件中读取数据,向Excel文件中写入数据,将Excel表格中的数据插入数据库,将数据库中的数据添加到Excel表

    POI 简介: POI是Apache软件基金会用Java编写的免费开源的跨平台的 Java API,Apache POI提供API给Java程序对Microsoft Office格式档案读和写的功能. ...

  6. 向HBase中导入数据3:使用MapReduce从HDFS或本地文件中读取数据并写入HBase(增加使用Reduce批量插入)

    前面我们介绍了: 向HBase中导入数据1:查询Hive后写入 向HBase中导入数据2:使用MapReduce从HDFS或本地文件中读取数据并写入HBase(只使用Map逐条查询) 为了提高插入效率 ...

  7. python读文件和写文件-python开发--从文件中读取数据和写入文件

    #! /usr/bin/env python -*- coding:utf-8 -*- """ @Author:gcan @Email:1528667112@qq.com ...

  8. java读取hadoop数据_从Hadoop URL中读取数据_hadoop 数据读取_hadoop读取文件

    3.5  Java接口 在本小节,我们要深入探索Hadoop的Filesystem类:与Hadoop的文件系统交互的API. 虽然我们主要关注的是HDFS的实现DistributedFileSyste ...

  9. C++实现从.txt文件中读取数据存入数组,将数组数据写入.txt文件

    声明: 编译器:vs2017 所有用到的.txt文件都是提前放在当前工程目录下的. 完整测试代码:github–Zhaotiedan 方法一:针对可以提前知道存入数组的大小 1.从.txt文件中读取数 ...

最新文章

  1. 数据结构与算法笔记(十五)—— 散列(哈希表)
  2. 台式计算机计量单位,计算机的计量单位以及常见的数据类型
  3. 阿里云数据库Mysql被黑
  4. 需求调研报告模板_2020年工业软管行业深度市场调研及投资策略建议报告-液体化学品增加对其需求...
  5. 正则表达式 基础认识
  6. Oracle执行计划稳固
  7. Android开发学习之ImageView手势拖拽、缩放、旋转
  8. I2S和PCM区别(二十)
  9. 黄淮学院计算机专业录取分数线2019,黄淮学院2020年录取分数线(附2017-2020年分数线)...
  10. caffe训练的实时可视化思路
  11. 帆软报表多行多条数据写入表_超多种类的报表模板,填上数据就能用,全拿走!...
  12. python const char_python C 扩展(转载)
  13. 【转】正则表达式–零宽断言详解
  14. NodeJs 多核多进程并行框架实作 - CNode
  15. 第一篇博客——开天辟地
  16. 奥维互动地图如何删除标签_奥维互动地图浏览器标签附件添加设置方法
  17. KEIL4烧写下载程序到STM32最小系统板
  18. Pr-快速上手-基本操作-教程
  19. 三种最常用的期货交易系统,99%的人都不知道
  20. QQ音乐推荐歌单API报错 invalid referer

热门文章

  1. python基础教程书籍-Python基础教程(第2版)
  2. Google云端语音识别app
  3. 四叶草启动linux黑屏,四叶草剧场黑屏进不去解决方法一览
  4. vue-seamless-scroll
  5. laydate报Uncaught TypeError: Cannot read property 'appendChild' of undefined
  6. FFMPEG 库移植到 VC 需要的步骤
  7. python中唯一的映射类型是什么_Python基础类型之字典(dict)
  8. 2018青岛大学计算机考研真题,2018年青岛大学师范学院880数学基础综合[专业硕士]之数学分析考研基础五套测试题...
  9. 自动执行任务_中小企业如何做运维自动化?
  10. Life is short, you need Python. ——Bruce Eckel