All Downloads are FREE. Search and download functionalities are using the official Maven repository.

holmos.webtest.junitextentions.parameters.csv.HolmosCSVUtils Maven / Gradle / Ivy

There is a newer version: 1.0.2u10
Show newest version
package holmos.webtest.junitextentions.parameters.csv;

import holmos.webtest.exceptions.HolmosFailedError;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;

import au.com.bytecode.opencsv.CSVReader;

/**
 * 操作csv文件的工具类
 * 
 * @author 吴银龙([email protected])
 * */
public class HolmosCSVUtils {
	/**
	 * 根据指定的csv文件路径来获取csv文件的读取器
	 * @param csvFilePath csv文件绝对路径
	 * */
	public static CSVReader getCsvReader(String csvFilePath){
		if(!new File(csvFilePath).exists()){
			throw new HolmosFailedError(csvFilePath+"文件不存在!请检查此处文件!");
		}try {
			return new CSVReader(new InputStreamReader(new FileInputStream(new File(csvFilePath)),"GBK"));
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}return null;
	}
	public static ArrayListgetAllValues(CSVReader csvReader){
		try {
			return (ArrayList) csvReader.readAll();
		} catch (IOException e) {
			e.printStackTrace();
		}return null;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy