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));
}
}
}*/
}