Close stream

This commit is contained in:
Reinhard Pointner 2016-03-05 21:06:20 +00:00
parent 93937680a7
commit b452414614
1 changed files with 9 additions and 8 deletions

View File

@ -214,16 +214,17 @@ public final class FileUtilities {
return destination;
}
public static List<String[]> readCSV(InputStream source, String charsetName, String separatorPattern) {
Scanner scanner = new Scanner(source, charsetName);
Pattern separator = Pattern.compile(separatorPattern);
List<String[]> rows = new ArrayList<String[]>(65536);
public static List<String[]> readCSV(InputStream source, String charsetName, String pattern) {
try (Scanner scanner = new Scanner(source, charsetName)) {
Pattern separator = Pattern.compile(pattern);
List<String[]> rows = new ArrayList<String[]>(65536);
while (scanner.hasNextLine()) {
rows.add(separator.split(scanner.nextLine()));
while (scanner.hasNextLine()) {
rows.add(separator.split(scanner.nextLine()));
}
return rows;
}
return rows;
}
public static Reader createTextReader(File file) throws IOException {