我有一个.txt
具有以下格式数据的文件(坐标)
0 1 12.56
2 0 -56.2
1 2 78.2
0 -56.2 2
-2 8 0
我使用以下代码将此数据导入。
public ArrayList<Point3d> loadFile(String filename) {
ArrayList<Point3d> words = new ArrayList<Point3d>();
try {
Scanner chopper = new Scanner(new File(filename));
while (chopper.hasNext()) {
double x=chopper.nextDouble();
double y=chopper.nextDouble();
double z=chopper.nextDouble();
Point3d p=new Point3d(x, y, z);
words.add(p);
// just calling nextLine will cause an exception at the end of the file unless you have an blank line there on purpose, so this makes sure it does
}
chopper.close();
} catch (Exception e) {
System.out.println(e);
}
return words;
}
导入工作正常。知道我想分开负坐标,正坐标我还想附加它们相应的索引值。
最后,我希望通过以下方式获得结果。
结果 :
positiveList= {{0,0,1,12.56},{2,1,2,78.2}}
negativeList={{1,2,0,-56.2},{3,0,-56.2,2},{4,-2,8,0}}
我怎样才能做到这一点。