I am trying to break some simple data from a .txt file. I found some useful structures on the Internet, but this was not enough to separate the data the way I wanted. I get a line like this:
{X:0.8940594 Y:0.6853521 Z:1.470214}
And I want to convert it like this:
0.8940594
0.6853521
1.470214
And then put them in the matrix in the order X = [], Y = [], Z = []; (data are the coordinates of the object)
Here is my code:
BufferedReader in = null; {
try {
in = new BufferedReader(new FileReader("file.txt"));
String read = null;
while ((read = in.readLine()) != null) {
String[] splited = read.split("\\s+");
for (String part : splited) {
System.out.println(part);
}
}
} catch (IOException e) {
System.out.println("There was a problem: " + e);
e.printStackTrace();
} finally {
try {
in.close();
} catch (Exception e) {
}
}
}
What do I need to add to my code to get the data the way I want?
Right now, with this code, I get this data:
{X:0.8940594
Y:0.6853521
Z:1.470214}
source
share