我正在用Java创建一个简单的keyllogger。键入的内容将写入文本文件。我有个问题。当我启动程序并键入内容时,文本文件会显示其键入的内容,但是当我停止程序并重新启动它并再次键入内容时,文本文件将没有我初次启动程序时键入的内容。如何防止重新创建文本文件。
这里是代码,
希望有人可以帮助我,提前致谢,最好的祝福,Srdjan,
使用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) {
}