import com.simplecsv.*; import com.simplecsv.annotation.*; CsvConfiguration configuration = new CsvConfiguration.Builder() .setDelimiter(',') .setQuoteChar('"') .setEscapeChar('\\') .build(); try { CsvReader csvReader = new CsvReader("path/to/file.csv", configuration); // ... } catch (FileNotFoundException e) { e.printStackTrace(); } try { CsvReader csvReader = new CsvReader("path/to/file.csv", configuration); List<MyDataObject> data = csvReader.readAll(MyDataObject.class); // ... } catch (ParseCsvException e) { e.printStackTrace(); } import com.simplecsv.*; import com.simplecsv.annotation.*; import java.io.FileNotFoundException; import java.util.List; public class SimpleCsvExceptionHandling { public static void main(String[] args) { CsvConfiguration configuration = new CsvConfiguration.Builder() .setDelimiter(',') .setQuoteChar('"') .setEscapeChar('\\') .build(); try { CsvReader csvReader = new CsvReader("path/to/file.csv", configuration); List<MyDataObject> data = csvReader.readAll(MyDataObject.class); // ... } catch (FileNotFoundException e) { e.printStackTrace(); } catch (ParseCsvException e) { e.printStackTrace(); } } public static class MyDataObject { @CsvColumn(name = "id") private int id; @CsvColumn(name = "name") private String name; // ... } }


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