I want to read in a simple text file and save it as an ArrayList. The file looks like so
0.2253
0.808
0.132
0.341
4.18546
8.65418
1.45535
0.341
and so on...
They will always be four lines and they will always be delimited by a blank space. Somehow I'd like to use that as the break point to begin the new array and pick back up with the first new number as index zero.
The numbers must be stored as strings.
I want to assign this data to an ArrayList such that
[0][0] = 0.2253
[0][1] = 0.808
[0][2] = 0.132
[0][3] = 0.341
[1][0] = 4.18546
[1][1] = 8.65418
[1][2] = 1.45535
[1][3] = 0.341
how can I do this using the structures of java i/o?
java io arraylist
So far I have this..
//array list data struc
ArrayList<String> array_list = new ArrayList<String>();
String component_doc = "/home/joao/document.txt"
Scanner inFile = null;
try
{
inFile = new Scanner(new File(component_doc));
}
catch (FileNotFoundException e)
{
e.printStackTrace();
}
while(inFile.hasNextLine())
{
array_list.add(inFile.nextLine());
}