diff --git a/src/main/java/org/apache/commons/csv/CSVParser.java b/src/main/java/org/apache/commons/csv/CSVParser.java index 9533a618..8550342a 100644 --- a/src/main/java/org/apache/commons/csv/CSVParser.java +++ b/src/main/java/org/apache/commons/csv/CSVParser.java @@ -134,6 +134,32 @@ import java.util.TreeMap; */ public final class CSVParser implements Iterable, Closeable { + /** + * Creates a parser for the given {@link File}. + * + *

Note: This method internally creates a FileReader using + * {@link java.io.FileReader#FileReader(java.io.File)} which in turn relies on the default encoding of the JVM that + * is executing the code. If this is insufficient create a URL to the file and use + * {@link #parse(URL, Charset, CSVFormat)}

+ * + * @param file + * a CSV file. Must not be null. + * @param charset + * A charset + * @param format + * the CSVFormat used for CSV parsing. Must not be null. + * @return a new parser + * @throws IllegalArgumentException + * If the parameters of the format are inconsistent or if either file or format are null. + * @throws IOException + * If an I/O error occurs + */ + public static CSVParser parse(final File file, final Charset charset, final CSVFormat format) throws IOException { + Assertions.notNull(file, "file"); + Assertions.notNull(format, "format"); + return new CSVParser(new InputStreamReader(new FileInputStream(file), charset), format); + } + /** * Creates a CSV parser using the given {@link CSVFormat}. * @@ -190,32 +216,6 @@ public final class CSVParser implements Iterable, Closeable { return new CSVParser(reader, format); } - /** - * Creates a parser for the given {@link File}. - * - *

Note: This method internally creates a FileReader using - * {@link java.io.FileReader#FileReader(java.io.File)} which in turn relies on the default encoding of the JVM that - * is executing the code. If this is insufficient create a URL to the file and use - * {@link #parse(URL, Charset, CSVFormat)}

- * - * @param file - * a CSV file. Must not be null. - * @param charset - * A charset - * @param format - * the CSVFormat used for CSV parsing. Must not be null. - * @return a new parser - * @throws IllegalArgumentException - * If the parameters of the format are inconsistent or if either file or format are null. - * @throws IOException - * If an I/O error occurs - */ - public static CSVParser parse(final File file, final Charset charset, final CSVFormat format) throws IOException { - Assertions.notNull(file, "file"); - Assertions.notNull(format, "format"); - return new CSVParser(new InputStreamReader(new FileInputStream(file), charset), format); - } - /** * Creates a parser for the given {@link String}. *