我有一個非常愚蠢的問題......我不知道如何將結果保存在輸出文件中,第二個數組保存在較低的行中。將結果保存到文件 - JAVA
這是如何保存:
DIST [0 10 13 10 6 18] PRED [-15 2 10 1 4]
我希望它保存這樣的:
dist[0 10 13 10 6 18 ]
pred[-15 2 5 1 4 ]
CODE:
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());
}
}
}
你又在寫什麼'文件? – Makoto
@Makoto編輯代碼 – 2012-12-07 07:15:35