Append Data To A File

来源:互联网 发布:高清图片 知乎 编辑:程序博客网 时间:2024/06/12 01:16

/** author:whxbb*/

    public void log(String fileName, String content) throws Exception
    {
        String logMsg = new Date().toLocaleString() + ":" + content + "/r/n";
        ByteBuffer bbf = ByteBuffer.wrap(logMsg.getBytes());
        File file = new File(fileName);
        if (!file.exists())file.createNewFile();
        boolean append = true;
        FileChannel wChannel = new FileOutputStream(file, append).getChannel();
        wChannel.write(bbf);
        wChannel.close();
    }

原创粉丝点击