CsvWriter&&CsvReader
有时候需要将一些数据以 .CSV文件形式保存,并在其他的地方要读取数据的时候,可以考虑用javacsv.jar里面的API来实现。
简单写了一下实现:
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import com.csvreader.CsvWriter;
public class CsvWriterTest {
public static void main(String[] args) throws IOException {
CsvWriter writer = new CsvWriter(new FileWriter(new File("./1.csv")),',');
writer.write("aa");
writer.write("bb");
writer.write("cc");
writer.endRecord();
writer.write("1");
writer.write("2");
writer.write("3");
writer.close();
System.out.println(writer.toString());
}
}
############################################################################
import java.io.IOException;
import com.csvreader.CsvReader;
public class CsvRederTest {
public static void main(String[] args) throws IOException {
CsvReader reader = new CsvReader("./1.csv ");
while (reader.readRecord()) {
String str = reader.getRawRecord();
System.out.println(str);
}
reader.close();
}
}