|
41 | 41 | * Because CSV appears in many different dialects, the parser supports many formats by allowing the |
42 | 42 | * specification of a {@link CSVFormat}. |
43 | 43 | * |
| 44 | + * The parser works record wise. It is not possible to go back, once a record has been parsed from the input stream. |
| 45 | + * |
44 | 46 | * <h4>Creating instances</h4> |
45 | 47 | * There are several static factory methods that can be used to create instances for various types of resources: |
46 | 48 | * <p> |
|
56 | 58 | * |
57 | 59 | * <h4>Parsing record wise</h4> |
58 | 60 | * <p> |
59 | | - * To parse a CSV input with tabs as separators, '"' (double-quote) as an optional value encapsulator, and comments |
60 | | - * starting with '#', you write: |
| 61 | + * To parse a CSV input from a file, you write: |
61 | 62 | * </p> |
62 | 63 | * |
63 | 64 | * <pre> |
64 | | - * Reader in = new StringReader("a\tb\nc\td"); |
65 | | - * Iterable<CSVRecord> parser = CSVFormat.DEFAULT |
66 | | - * .withCommentStart('#') |
67 | | - * .withDelimiter('\t') |
68 | | - * .withQuoteChar('"').parse(in); |
69 | | - * for (CSVRecord csvRecord : parse) { |
| 65 | + * File csvData = new File("/path/to/csv"); |
| 66 | + * CSVParser parser = CSVParser.parse(csvData, CSVFormat.RFC4180); |
| 67 | + * for (CSVRecord csvRecord : parser) { |
70 | 68 | * ... |
71 | | - * } |
| 69 | + * } |
72 | 70 | * </pre> |
73 | 71 | * |
74 | 72 | * <p> |
75 | | - * To parse CSV input in a given format like Excel, you write: |
| 73 | + * This will read the parse the contents of the file using the |
| 74 | + * <a href="http://tools.ietf.org/html/rfc4180" target="_blank">RFC 4180</a> format. |
| 75 | + * </p> |
| 76 | + * |
| 77 | + * <p> |
| 78 | + * To parse CSV input in a format like Excel, you write: |
76 | 79 | * </p> |
77 | 80 | * |
78 | 81 | * <pre> |
79 | | - * Reader in = new StringReader("a;b\nc;d"); |
80 | | - * Iterable<CSVRecord> parser = CSVFormat.EXCEL.parse(in); |
81 | | - * for (CSVRecord record : parser) { |
| 82 | + * CSVParser parser = CSVParser.parse(csvData, CSVFormat.EXCEL); |
| 83 | + * for (CSVRecord csvRecord : parser) { |
82 | 84 | * ... |
83 | 85 | * } |
84 | 86 | * </pre> |
85 | 87 | * |
| 88 | + * <p> |
| 89 | + * If the predefined formats don't match the format at hands, custom formats can be defined. More information about |
| 90 | + * customising CSVFormats is available in {@link CSVFormat CSVFormat JavaDoc}. |
| 91 | + * </p> |
| 92 | + * |
86 | 93 | * <h4>Parsing completely into memory</h4> |
87 | 94 | * <p> |
88 | 95 | * You may also get a List of records: |
|
0 commit comments