zoukankan      html  css  js  c++  java
  • 读取csv文件

    package dpp.file.controller;

    import java.io.BufferedReader;
    import java.io.FileInputStream;
    import java.io.InputStreamReader;
    import java.util.ArrayList;

    public class CSVFileUtil {

    // CSV文件编码
    public static final String ENCODE = "GBK";

    private FileInputStream fis = null;
    private InputStreamReader isw = null;
    private BufferedReader br = null;

    public CSVFileUtil(String filename) throws Exception {
    fis = new FileInputStream(filename);
    isw = new InputStreamReader(fis, ENCODE);
    br = new BufferedReader(isw);
    }

    /**
    * 从CSV文件流中读取一个CSV行。
    *
    * @throws Exception
    */
    public ArrayList<String> readLine() throws Exception {
    boolean bReadNext = true;
    int rowNum = 0;
    ArrayList<String> strArray = new ArrayList<String> ();
    while (bReadNext) {
    rowNum++;
    String strReadLine = br.readLine();
    if (strReadLine == null) {
    bReadNext = false;
    }
    if(rowNum > 1) {
    if(!(strReadLine == null || strReadLine == "")) {
    strArray.add(strReadLine);
    }
    }
    }
    return strArray;
    }

    /*public static void main(String[] args) throws Exception {
    CSVFileUtil csvFileUtil = new CSVFileUtil("C://Users//Administrator//Desktop//设备数据.csv");
    ArrayList<String> result = csvFileUtil.readLine();
    if(result.size() > 0) {
    for(int i = 0; i < result.size(); i++) {
    System.out.println(i + "=======" + result.get(i));
    }
    }
    }*/
    }

  • 相关阅读:
    第6周编程题:零基础学Java
    帆软报表软件学习计划
    北大软件工程——第八周:面向对象设计2
    hdu1264 Counting Squares
    hdu1264 Counting Squares
    poj1151 Atlantis(线段树+扫描线)
    poj1151 Atlantis(线段树+扫描线)
    bzoj4653 [Noi2016]区间
    bzoj4653 [Noi2016]区间
    Tyvj1043
  • 原文地址:https://www.cnblogs.com/vofill/p/5412966.html
Copyright © 2011-2022 走看看