I have written a script in which I read in .txt files to arrays
. It works perfectly but I'm curious if there is a more efficient way of reading the .txt files in.
I have this:
try {
String line;
filestart = new BufferedReader(new FileReader("C:\\path\\file.txt));
for (line = filestart.readLine(); line !=null; line = filestart.readLine()) {
array.add (line);
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
Is there a function that combines BufferedReader
and FileReader
?
How would Scanner
compare with what I have?