|
30 | 30 | import java.io.UnsupportedEncodingException; |
31 | 31 | import java.net.URL; |
32 | 32 | import java.nio.charset.Charset; |
| 33 | +import java.nio.file.Path; |
33 | 34 | import java.util.ArrayList; |
34 | 35 | import java.util.Arrays; |
35 | 36 | import java.util.Iterator; |
@@ -192,6 +193,33 @@ public static CSVParser parse(final InputStream inputStream, final String charse |
192 | 193 | return parse(new InputStreamReader(inputStream, charset), format); |
193 | 194 | } |
194 | 195 |
|
| 196 | + /** |
| 197 | + * Creates a parser for the given {@link File}. |
| 198 | + * |
| 199 | + * <p><strong>Note:</strong> This method internally creates a FileReader using |
| 200 | + * {@link java.io.FileReader#FileReader(java.io.File)} which in turn relies on the default encoding of the JVM that |
| 201 | + * is executing the code. If this is insufficient create a URL to the file and use |
| 202 | + * {@link #parse(URL, Charset, CSVFormat)}</p> |
| 203 | + * |
| 204 | + * @param path |
| 205 | + * a CSV file. Must not be null. |
| 206 | + * @param charset |
| 207 | + * A charset |
| 208 | + * @param format |
| 209 | + * the CSVFormat used for CSV parsing. Must not be null. |
| 210 | + * @return a new parser |
| 211 | + * @throws IllegalArgumentException |
| 212 | + * If the parameters of the format are inconsistent or if either file or format are null. |
| 213 | + * @throws IOException |
| 214 | + * If an I/O error occurs |
| 215 | + * @since 1.5 |
| 216 | + */ |
| 217 | + public static CSVParser parse(final Path path, final Charset charset, final CSVFormat format) throws IOException { |
| 218 | + Assertions.notNull(path, "path"); |
| 219 | + Assertions.notNull(format, "format"); |
| 220 | + return parse(path.toFile(), charset, format); |
| 221 | + } |
| 222 | + |
195 | 223 | /** |
196 | 224 | * Creates a CSV parser using the given {@link CSVFormat} |
197 | 225 | * |
|
0 commit comments