You are not reading the files at once (you would need to use threading to do that).
The issue is in your simplify
method.
line = input.readLine();
while (line != null) {
... should become:
while ((line = input.readLine()) != null)
The reason for this is that you are calling readLine
only once, and iterating only over the first line's value otherwise.
With the proper while
loop you pipe the value of the readLine
call to the non-null
condition after assigning it to your line
variable.
You can then do whatever you want with the line
String
you manipulated in your while
loop, such as adding it to an array
or Collection
, as you suggested in your comment.
For instance:
public static List<String> simplify(BufferedReader input) throws IOException {
String line = null;
List<String> result = new ArrayList<String>();
while ((line = input.readLine()) != null) {
result.add(line.replaceAll ("[^a-zA-Z0-9 ]", "").toLowerCase());
}
return result;
}
... then in your main
method...
List<String> foo = simplify(reader);