How would you be able to import a .txt file and then place each line into an array list as an object, but have each object be an array.
The .txt file looks like this:
1 a 1 2
1 b 0 1
2 a 2 3
2 b 0 3
3 a 3 1
3 b 0 3
I wanted to be able to make each line an object array like so where so that i could call upon the object and the specific point in the array:
<1,a,1,2>
<1,b,0,1>
<2,a,2,3>
<2,b,0,3>
<3,a,3,1>
<3,b,0,3>
and then have an array list where each line (there can be any amount of line hence why i chose an array list) is one thing in the array list. kinda like <line1,line2,line3,etc..> so i can use the array list and then the values in the individual arrays within the array list.
This is the code that I currently have and i don't know where to go from here. I am using a buffered reader
Scanner input = new Scanner(System.in); // Create a Scanner object
String inputString = input.nextLine();
try {
BufferedReader FSMreader = new BufferedReader(new FileReader(args[0]));
List<FSMline> line = new ArrayList<>();
List<String> currentState = new ArrayList<>();
List<String> inputChoice = new ArrayList<>();
List<String> outputFunction = new ArrayList<>();
List<String> nextState = new ArrayList<>();
String lines;
while ((lines = FSMreader.readLine()) != null) {
line.add(new FSMline(lines.split(" ")));
}
Any help is appreciated because i'm running out of time on a deadline in a class that i am struggling to understand.
thanks
FSMlineconstructor. Don't do that anymore and fix the type ofline, then you should be done.List<FSMline> line = new ArrayList<>()toList<ArrayList<String>> line = new ArrayList<>(). If you do want to use a custom object, you will need to assign your inner arrays to that object