Here is a sample input text file:
some text
one more line of text
another line
and one more
1 23 3
2 34 4
5 12 4
3 23 8
I need to extract each column of numerical values and perform some mathematical operation on it.
This is what i have tried till now:
Path inputFile = Paths.get(args[0]);
try{
ArrayList<String> lines = (ArrayList<String>) Files.readAllLines(inputFile, Charset.defaultCharset());
ArrayList<String []> columns = new ArrayList<>();
for(String line : lines){
columns.add(line.split("\\s"));
}
// Now for each line you have columns.
for(String [] s : columns){
System.out.println(Arrays.toString(s));
}
But its just not right and i'm unable to move from this deadlock. Any help would be greatly appreciated..
Integer.parseInt(columns.get(4/*line 4*/)[2/*23*/])to convert one of those strings to an integer.