Java Path File Content appendToLog(String content, Path newFile)

Here you can find the source of appendToLog(String content, Path newFile)

Description

append To Log

License

LGPL

Declaration

public static void appendToLog(String content, Path newFile) 

Method Source Code


//package com.java2s;
//License from project: LGPL 

import java.io.BufferedWriter;
import java.io.IOException;

import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.OpenOption;
import java.nio.file.Path;

import java.nio.file.StandardOpenOption;

public class Main {
    public static void appendToLog(String content, Path newFile) {
        //Writing to file
        try (BufferedWriter writer = Files.newBufferedWriter(newFile, Charset.defaultCharset(),
                new OpenOption[] { StandardOpenOption.APPEND })) {
            writer.append(content);//w w w . j  a  v  a2 s  .c  om
            writer.append("\n");
            writer.flush();
        } catch (IOException exception) {
            System.out.println("Error writing to file");
        }
    }
}

Related

  1. assertSameContent(String expectedFilePath, String actualFilePath)
  2. contentEquals(Path leftPath, Path rightPath)
  3. fileContent(final Path p)
  4. fileContent(final String filePath)