Tag: coded head close resolves ACS har write DMI Import
First, be prepared to download a Javacsv.jar rack package
public void Readecsv () {
try {
ArrayList<String[]> csvList = new ArrayList<String[]>(); //用来保存数据 //注明:或者可以通过前端上传的文件,用一个方法获取上传文件名uploadName(String) String csvFilePath = "C:\\Users\\Administrator\\Desktop/05122017.csv"; CsvReader reader = new CsvReader(csvFilePath,‘,‘,Charset.forName("GBK")); //解决中文编码 reader.readHeaders(); // 跳过表头 如果需要表头的话,不要写这句。 while(reader.readRecord()){ //逐行读入除表头的数据 csvList.add(reader.getValues()); } reader.close(); for(int row=0;row<csvList.size();row++){
String cell = csvlist.get (row) [0]; You can specify the fetch content by obtaining the data in column No. 0 of Row row
System.out.println("姓名:"+cell) } }catch(Exception ex){ System.out.println(ex); }
}
/**
- Writing to a CSV file
*/``
public void Writecsv () {
try {
String csvFilePath = "E:\\xb:/05122017.csv"; CsvWriter wr =new CsvWriter(csvFilePath,‘,‘,Charset.forName("SJIS")); String[] contents = {"aaaaa","bbbbb","cccccc","ddddddddd"}; wr.writeRecord(contents); wr.close(); } catch (IOException e) { e.printStackTrace();
}
Java read import CSV format file