<dependency> <groupId>com.github.darukframework</groupId> <artifactId>simplecsv</artifactId> <version>1.6</version> </dependency> import com.github.darukframework.simplecsv.CsvWriter; import com.github.darukframework.simplecsv.CsvReader; import java.io.IOException; import java.util.Arrays; import java.util.List; public class CsvExample { public static void main(String[] args) throws IOException { exportData(); importData(); } private static void exportData() throws IOException { CsvWriter writer = new CsvWriter("/path/to/output.csv"); List<String> headers = Arrays.asList("Name", "Age", "City"); writer.writeHeaders(headers); List<List<String>> dataRows = Arrays.asList( Arrays.asList("John Doe", "25", "New York"), Arrays.asList("Jane Smith", "30", "Los Angeles") ); writer.writeRows(dataRows); writer.close(); } private static void importData() throws IOException { CsvReader reader = new CsvReader("/path/to/input.csv"); List<String> headers = reader.getHeaders(); List<List<String>> dataRows = reader.readRows(); for (List<String> rowData : dataRows) { } reader.close(); } }


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