小编Mau*_*ull的帖子

Java FileOutputStream字符串编写

我一直在使用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");
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

java string file-io fileoutputstream

4
推荐指数
1
解决办法
2万
查看次数

标签 统计

file-io ×1

fileoutputstream ×1

java ×1

string ×1