我有一个非常愚蠢的问题......我不知道如何将结果保存在第二个数组保存在下一行的输出文件中。
它是这样保存的:
距离 [0 10 13 10 6 18 ] 预测 [-15 2 5 1 4 ]
我希望它像这样保存:
dist[0 10 13 10 6 18 ]
pred[-15 2 5 1 4 ]
代码:
try{
outputFile = new File("Out0304.txt");
out = new FileWriter(outputFile);
out.write("\n" + "dist[");
out.write("\n");
for (Top way : tops){
out.write(way.shortest_path + " ");
}
out.write("]\n");
out.write("\n");
out.write("\n" + "pred[");
for (Top ww : tops){
if (ww.previous != null) {
out.write(ww.previous.number + " ");
}
else{
out.write("-1");
}
}
out.write("] \n ");
out.close();
}
catch (IOException e){
System.out.println("Blad: " + e.toString());
}
}
}