我想从具有以下格式的文件中拆分数据:{[(1;1;2),(5;1;2),(5;1;1)],[(1;3;2),( 5;3;2),(5;1;2)]}
这是我的Java方法:
public void createFromFile(String filename) throws IOException{
BufferedReader br = new BufferedReader(new FileReader(filename));
String s;
while ((s = br.readLine()) != null)
{
s = s.replace("{", "").replace("}", "").replace("]", "").replace(",", "");
ArrayList<Surface> sf = new ArrayList<Surface>();
for(String s1: s.split("\\["))
{ // <== not splitting here
ArrayList<Point> tp = new ArrayList<Point>();
for(String s2: s1.split("\\("))
{ // <== here neither
String[] s3 = s2.split(";");
tp.add(new Point(Double.valueOf(s3[0]),Double.valueOf(s3[1]),Double.valueOf(s3[2])));
}
sf.add(new Surface((Point[]) tp.toArray()));
}
convShape.add(new Body((Surface[])sf.toArray()));
}
}
为什么不s.split("\\[")
拆分s.split("\\(")
s?