【发布时间】:2016-11-23 03:38:11
【问题描述】:
大家好,我需要我的程序能够存储多个输出,但它只是在文本文件中一遍又一遍地覆盖相同的字符串(总计)。我怎样才能让它写多个答案而不是覆盖它?谢谢你:)
static int boys;
static int girls;
static int total;
public static void program() {
System.out.println("enter number of girls: ");
girls = input.nextInt();
System.out.println("enter number of boys: ");
boys = input.nextInt();
total = boys+girls;
System.out.println(total);
}
private static Formatter x;
public void openFile () {
try {
x = new Formatter("income.txt");
}
catch(Exception e) {
System.out.println("You have an error");
}
}
public static void addRecords(){
x.format("%s%s%s", " 19", " James", " A");
x.format("%s%s", "\n", total);
}
public void closeFile(){
x.close();
}
【问题讨论】:
标签: java text-files overwrite