有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

使用java在文件中逐个使用for循环写入行

for(i=0;i<10;i++){
    String output = output + "Result "+ i +" : "+ ans +"\n";   //ans from other logic
    FileWriter f0 = new FileWriter("output.txt");
    f0.write(output);
}

但它不起作用, 请为appendPrintWriter方法提供一些帮助,我不知道如何使用这些方法

我需要像这样的文件输出

Result 1 : 45           //here 45 is ans
Result 2 : 564856
Result 3 : 879
.
.
.
.
Result 10 : 564

谢谢


共 (0) 个答案