将结果写入Java中的文本文件,并在每次启动程序时停止创建新文件

问题描述 投票:0回答:1

我正在用Java创建一个简单的keyllogger。键入的内容将写入文本文件。我有个问题。当我启动程序并键入内容时,文本文件会显示其键入的内容,但是当我停止程序并重新启动它并再次键入内容时,文本文件将没有我初次启动程序时键入的内容。如何防止重新创建文本文件。

这里是代码,

Picture, Code 1

Picture, Code 2

希望有人可以帮助我,提前致谢,最好的祝福,Srdjan,

java text-files
1个回答
0
投票

使用FileOutputStream附加到文件。

try {
        File file = new File("output-file.txt");
        //This true parameter to FileOutputStream
        // makes sure that the file is appended and not over written 
        FileOutputStream fos = new FileOutputStream(file, true);
        System.setOut(new PrintStream(fos));
    } catch(FileNotFoundException e) {

    }
© www.soinside.com 2019 - 2024. All rights reserved.