-1

为什么我的程序一遍又一遍地写入文件而不是添加数据?

我想写入文件,但它总是删除以前的并写入新的......

BufferedWriter writer = null;
    try {

    writer = new BufferedWriter(new FileWriter("koce_podatki.txt", true));
    //WRITES 1 LINE TO FILE AND CHANGES LINE
    writer.write(temp);
    writer.newLine();
    writer.close();
    } catch (Exception e) {

    }

    try {

    writer = new BufferedWriter(new FileWriter("s_koce.txt", true));
    //WRITES 1 LINE TO FILE AND CHANGES LINE
    writer.write(ime.getText());
    writer.newLine();
    writer.close();
    } catch (Exception e) {

    }
4

1 回答 1

0

我使用了thics,它起作用了:

try {
    PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("koce_podatki.txt", true)));
    out.println(temp);
    out.close();
} catch (IOException e) {
    //oh noes!
}
于 2013-01-26T15:45:09.460 回答