import com.opencsv.CSVReader; import com.opencsv.CSVWriter; try { CSVReader reader = new CSVReader(new FileReader("path/to/your/csvfile.csv")); String[] nextLine; while ((nextLine = reader.readNext()) != null) { for (String item : nextLine) { System.out.print(item + " "); } System.out.println(); } reader.close(); } catch (IOException e) { e.printStackTrace(); } try { CSVWriter writer = new CSVWriter(new FileWriter("path/to/your/csvfile.csv")); String[] header = {"Name", "Age", "Location"}; writer.writeNext(header); String[] data1 = {"John Doe", "25", "USA"}; String[] data2 = {"Jane Smith", "30", "Canada"}; writer.writeNext(data1); writer.writeNext(data2); writer.close(); } catch (IOException e) { e.printStackTrace(); }


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