diff --git a/src/main/java/org/apache/commons/csv/CSVParser.java b/src/main/java/org/apache/commons/csv/CSVParser.java index abca1a80..591a4bdc 100644 --- a/src/main/java/org/apache/commons/csv/CSVParser.java +++ b/src/main/java/org/apache/commons/csv/CSVParser.java @@ -41,6 +41,8 @@ import java.util.NoSuchElementException; * Because CSV appears in many different dialects, the parser supports many formats by allowing the * specification of a {@link CSVFormat}. * + * The parser works record wise. It is not possible to go back, once a record has been parsed from the input stream. + * *

Creating instances

* There are several static factory methods that can be used to create instances for various types of resources: *

@@ -56,33 +58,38 @@ import java.util.NoSuchElementException; * *

Parsing record wise

*

- * To parse a CSV input with tabs as separators, '"' (double-quote) as an optional value encapsulator, and comments - * starting with '#', you write: + * To parse a CSV input from a file, you write: *

* *
- * Reader in = new StringReader("a\tb\nc\td");
- * Iterable<CSVRecord> parser = CSVFormat.DEFAULT
- *     .withCommentStart('#')
- *     .withDelimiter('\t')
- *     .withQuoteChar('"').parse(in);
- *  for (CSVRecord csvRecord : parse) {
- *     ...
- *  }
- * 
- * - *

- * To parse CSV input in a given format like Excel, you write: - *

- * - *
- * Reader in = new StringReader("a;b\nc;d");
- * Iterable<CSVRecord> parser = CSVFormat.EXCEL.parse(in);
- * for (CSVRecord record : parser) {
+ * File csvData = new File("/path/to/csv");
+ * CSVParser parser = CSVParser.parse(csvData, CSVFormat.RFC4180);
+ * for (CSVRecord csvRecord : parser) {
  *     ...
  * }
  * 
* + *

+ * This will read the parse the contents of the file using the + * RFC 4180 format. + *

+ * + *

+ * To parse CSV input in a format like Excel, you write: + *

+ * + *
+ * CSVParser parser = CSVParser.parse(csvData, CSVFormat.EXCEL);
+ * for (CSVRecord csvRecord : parser) {
+ *     ...
+ * }
+ * 
+ * + *

+ * If the predefined formats don't match the format at hands, custom formats can be defined. More information about + * customising CSVFormats is available in {@link CSVFormat CSVFormat JavaDoc}. + *

+ * *

Parsing completely into memory

*

* You may also get a List of records: