import au.com.bytecode.opencsv.CSVReader; import au.com.bytecode.opencsv.CSVReader; import java.io.FileReader; import java.io.IOException; public class CSVReaderExample { public static void main(String[] args) { try { CSVReader reader = new CSVReader(new FileReader("path/to/csvfile.csv"), ','); String[] nextLine; while ((nextLine = reader.readNext()) != null) { for (String data : nextLine) { System.out.println(data); } } reader.close(); } catch (IOException e) { e.printStackTrace(); } } } import au.com.bytecode.opencsv.CSVWriter; import java.io.FileWriter; import java.io.IOException; public class CSVWriterExample { public static void main(String[] args) { try { CSVWriter writer = new CSVWriter(new FileWriter("path/to/csvfile.csv"), ','); String[] data1 = {"John", "Doe", "john.doe@example.com"}; String[] data2 = {"Jane", "Smith", "jane.smith@example.com"}; writer.writeNext(data1); writer.writeNext(data2); writer.close(); } catch (IOException e) { e.printStackTrace(); } } }


上一篇:
下一篇:
切换中文