写文件
public static void main(String[] args) throws Exception {
File file = new File("e:\\write.csv");
Writer writer = new FileWriter(file);
CSVWriter csvWriter = new CSVWriter(writer, ',');
String[] strs = {"abc" , "def" , "opq"};
csvWriter.writeNext(strs);
csvWriter.close();
}
读文件
public void Read(String dir) throws Exception { File csv = new File(dir + "/file", "readerTest.csv"); CSVReader reader = new CSVReader(new InputStreamReader(new FileInputStream(csv), "GBK"), ','); String [] header = reader.readNext(); //用readnext读取之后就不存在于stream中了 for (String s : header) { System.out.print(s + ","); } System.out.println(""); List<String[]> list = reader.readAll(); System.out.println(list.get(0)[0]); System.out.println(""); }