我一直遇到 Java 文件的问题。它的设计目的是在测试文件中逐行写入日志。不幸的是,每次我调用它时它都会覆盖同一行。
如果有人可以提供帮助,我将永远感激不尽,因为这一直把我逼上绝路!
代码如下。
public abstract class Log {
protected static String DefaultLogFileLocation = "c:\\LOG.txt";
public static void ToFile(String pInputString) {
FileOutputStream pOUTPUT;
PrintStream pPRINT;
try
{
pOUTPUT = new FileOutputStream(DefaultLogFileLocation);
pPRINT = new PrintStream(pOUTPUT);
pPRINT.println (pInputString + "\n");
pPRINT.close();
}
catch (Exception e)
{
System.err.println ("Error writing to file");
}
}
}