Java UTF File Write getUTF8FileAppendWriter(String filename)

Here you can find the source of getUTF8FileAppendWriter(String filename)

Description

get UTF File Append Writer

License

Open Source License

Declaration

public static Writer getUTF8FileAppendWriter(String filename) throws FileNotFoundException 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.io.*;

import java.nio.charset.StandardCharsets;
import java.nio.file.Path;
import java.nio.file.Paths;

public class Main {
    /**//from w ww.  j  a  v a 2 s . c o m
     * current working directory. Can be changed if needed
     */
    private static String cwd = ".";

    public static Writer getUTF8FileAppendWriter(String filename) throws FileNotFoundException {
        return new BufferedWriter(
                new OutputStreamWriter(new FileOutputStream(getFile(filename), true), StandardCharsets.UTF_8));
    }

    public static File getFile(String path) {
        return getPath(path).toFile();
    }

    public static Path getPath(String path) {
        Path p = Paths.get(path);
        if (p.isAbsolute())
            return p;
        else
            // making this absolute protects against the CWD being added twice
            return Paths.get(cwd, path).toAbsolutePath();
    }
}

Related

  1. asPrintWriterUTF8(OutputStream out)
  2. getBufferedUTF8Writer(File file)
  3. getUTF8FileWriter(File f)
  4. getUTF8Writer(OutputStream os)
  5. getUTF8Writer(String file)
  6. utf8Writer(File file)