I'd like to populate an array list with lines from an input file, the input file looks like this:
7f00000000000000000000000000000000000000000000000000000000000000027f00000000000000000000000000000000000000000000000000000000000000027f00000000000000000000000000000000000000000000000000000000000000020101
7f00000000000000000000000000000000000000000000000000000000000000037f00000000000000000000000000000000000000000000000000000000000000037f00000000000000000000000000000000000000000000000000000000000000030101
7f00000000000000000000000000000000000000000000000000000000000000047f00000000000000000000000000000000000000000000000000000000000000047f00000000000000000000000000000000000000000000000000000000000000040101
7f00000000000000000000000000000000000000000000000000000000000000057f00000000000000000000000000000000000000000000000000000000000000057f00000000000000000000000000000000000000000000000000000000000000050101
7f00000000000000000000000000000000000000000000000000000000000000067f00000000000000000000000000000000000000000000000000000000000000067f00000000000000000000000000000000000000000000000000000000000000060101
The data object in Java that I'd like to create based on this would have each one of those lines as a new string, and they would live together in a list, so to speak*.
So, in my attempt to read in the lines of the file into different components of this array list, I can't figure out where I need to declare the array list in my main program. My plan is to populate it in a separate method:
import java.io.*;
import java.util.Scanner;
import java.util.List;
import java.util.Array;
import java.util.ArrayList;
class evmTest {
public static void main(String[] args) {
Array<String> inputLinesObject = new ArrayList<String>();
// populate from file
inputLinesObject = readFile("/Users/s.matthew.english/codes.txt", inputLinesObject);
System.out.println(Array.toString(inputLinesObject));
}
private static void readFile(String fileName, Array<String> inputLines) {
try {
File file = new File(fileName);
Scanner scanner = new Scanner(file);
while (scanner.hasNextLine()) {
// System.out.println(scanner.nextLine());
inputLines.add(scanner.nextLine());
}
scanner.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
}
return inputLines;
}
}
Maybe I can initially instantiate it as null, and then pass that null array list to the method to be populated?
* The terms in that last sentence are not totally precise- please forgive me- I'm re-adjusting to the vocabulary of Java, nevertheless I think it should be clear enough what I'm trying to do. If not please let me know and I'll be happy to clarify.