<dependency> <groupId>org.apache.commons</groupId> <artifactId>commons-csv-sandbox</artifactId> <version>1.1-SNAPSHOT</version> </dependency> import org.apache.commons.csv.*; public class CSVParserExample { public static void main(String[] args) throws Exception { CSVParser parser = new CSVParserBuilder() .withSeparator(',') .withQuoteChar('"') .build(); CSVReader csvReader = new CSVReaderBuilder(new FileReader("example.csv")) .withCSVParser(parser) .build(); String[] record; while ((record = csvReader.readNext()) != null) { for (String value : record) { System.out.print(value + " "); } System.out.println(); } csvReader.close(); } } import org.apache.commons.csv.*; public class CSVGeneratorExample { public static void main(String[] args) throws Exception { .withSeparator(',') .withQuoteChar('"') .build(); csvPrinter.printRecord("Name", "Age", "City"); csvPrinter.printRecord("John Doe", 30, "New York"); csvPrinter.printRecord("Jane Smith", 25, "London"); csvPrinter.flush(); csvPrinter.close(); } }


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