<dependency> <groupId>net.sf.supercsv</groupId> <artifactId>super-csv-java8</artifactId> <version>2.4.0</version> </dependency> groovy implementation 'net.sf.supercsv:super-csv-java8:2.4.0' import org.supercsv.io.CsvListReader; import org.supercsv.prefs.CsvPreference; import java.io.FileReader; import java.io.IOException; import java.util.List; public class CsvReaderExample { public static void main(String[] args) { String csvFilePath = "path/to/your/csv/file.csv"; try (CsvListReader csvReader = new CsvListReader(new FileReader(csvFilePath), CsvPreference.STANDARD_PREFERENCE)) { List<String> record; while ((record = csvReader.read()) != null) { record.stream() .map(String::toUpperCase) .forEach(System.out::println); } } catch (IOException e) { e.printStackTrace(); } } } import org.supercsv.io.CsvListWriter; import org.supercsv.prefs.CsvPreference; import java.io.FileWriter; import java.io.IOException; import java.util.ArrayList; import java.util.List; public class CsvWriterExample { public static void main(String[] args) { String csvFilePath = "path/to/your/csv/file.csv"; try (CsvListWriter csvWriter = new CsvListWriter(new FileWriter(csvFilePath), CsvPreference.STANDARD_PREFERENCE)) { List<String> record = new ArrayList<>(); record.add("John"); record.add("Doe"); record.add("john.doe@example.com"); csvWriter.write(record); } catch (IOException e) { e.printStackTrace(); } } }


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