我的 java 程序只向 txt 文件写入一行。
代码:主要:
package hu.hymosi.tut;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.util.Random;
public class Main {
public static void main(String[] args) {
PrintWriter out = null;
frameworkcucc fw = new frameworkcucc();
for (int i = 1; i < 100; i++) {
Random rand = new Random();
System.out.println(i);
try {
out = new PrintWriter("valtozok.txt");
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
int kiirando = rand.nextInt();
fw.writetotext(kiirando, out);
}
}
}
框架cucc:
package hu.hymosi.tut;
import java.io.PrintWriter;
public class frameworkcucc {
public void writetotext(int write, PrintWriter writer) {
writer.print(write + "\n");
}
}
如果我运行程序,它只会在我的 txt 文件中写入一行。什么是错误,我该如何解决?