-
Notifications
You must be signed in to change notification settings - Fork 0
/
IOUtils.java
42 lines (36 loc) · 1.18 KB
/
IOUtils.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/*
* Useful I/O operations.
*
* Copyright (C) 2013 Lisa Vitolo <[email protected]>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the Creative Commons
* Attribution-NonCommercial-ShareAlike 3.0 license.
* You should have received a copy of the license with this product.
* Otherwise, visit http://creativecommons.org/licenses/by-nc-sa/3.0/
*/
import java.util.List;
import java.util.LinkedList;
import java.io.FileReader;
import java.io.BufferedReader;
import java.io.IOException;
public class IOUtils
{
/* Reads a text file as a list of rows. */
public static List<String> readlines(String input)
{
List<String> lines = new LinkedList<>();
try {
BufferedReader br = new BufferedReader( new FileReader(input) );
String line;
while ((line = br.readLine()) != null) {
lines.add(line);
}
br.close();
} catch (IOException e) {
System.err.println("Could not read \"" + input + "\": " + e.getLocalizedMessage());
System.exit(-1);
}
return lines;
}
}