我有以下问题。字符串变量打印在 txt 文件上
```
1 3 1.
```
实际上,它必须输出
```
1 1 1
1 2 1
1 3 1
```
我不知道代码中的错误在哪里。似乎代码每次都在覆盖,最后一条语句被覆盖。谁能帮助我
public class RankingExportTest {
private static final String LINE_SEPARATOR = "\r\n";
Set<String> exportGraph(DirectedUnweightedGraph<CommonNode, CommonEdge<CommonNode>> graph) throws IOException {
Set<String> rows = new LinkedHashSet<>((int)graph.getEdgeCount());
for(CommonNode fromNode: graph.getNodes()) {
for(CommonNode toNode: graph.adjacentTo(fromNode)) {
String row = String.format(
"%d %d 1",
fromNode.getIdentity().intValue(),
toNode.getIdentity().intValue()
);
rows.add(row);
System.out.println(row);
try {
PrintWriter out;
out = new PrintWriter( "/Users/......" );
out.print(rows);
out.close();
//System.out.println(row);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
}
return rows;
}