Java Utililty Methods UTF File Write

List of utility methods to do UTF File Write

Description

The list of methods to do UTF File Write are organized into topic(s).

Method

PrintWriterasPrintWriterUTF8(OutputStream out)
Create a print writer that uses UTF-8 encoding
return new PrintWriter(asUTF8(out));
BufferedWritergetBufferedUTF8Writer(File file)
Creates a BufferedWriter for UTF-8-encoded files
return new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), Charset.forName("UTF-8")));
WritergetUTF8FileAppendWriter(String filename)
get UTF File Append Writer
return new BufferedWriter(
        new OutputStreamWriter(new FileOutputStream(getFile(filename), true), StandardCharsets.UTF_8));
WritergetUTF8FileWriter(File f)
get UTF File Writer
return getUTF8FileWriter(f.getPath());
WritergetUTF8Writer(OutputStream os)
Create a new file writer that uses UTF-8.
return new OutputStreamWriter(os, StandardCharsets.UTF_8);
WritergetUTF8Writer(String file)
get UTF Writer
return new PrintWriter(new OutputStreamWriter(new FileOutputStream(file), StandardCharsets.UTF_8));
Writerutf8Writer(File file)
Creates a writer whose character encoding is set to "UTF-8".
return utf8Writer(file, false);
Writerutf8Writer(final File f)
Creates a Writer that writes to the given file, converting chars to bytes using the UTF-8 charset.
return new OutputStreamWriter(new FileOutputStream(f), UTF8);
voidwriteFile(byte[] data, String outfile)
write File
FileOutputStream fout = null;
FileChannel fc = null;
try {
    fout = new FileOutputStream(outfile);
    fc = fout.getChannel();
    fc.transferFrom(Channels.newChannel(new ByteArrayInputStream(data)), 0, data.length);
} catch (Exception e) {
    e.printStackTrace();
...
booleanwriteFile(String fileName, ArrayList data, String outputFolder)
write the contents of given data (list of lines) under given fileName in given outputFolder
try {
    Path outputFile = Paths.get(outputFolder + File.separator + fileName);
    createFoldersForPath(outputFile.toAbsolutePath().toString());
    Files.write(outputFile, data, Charset.forName("UTF-8"));
    return true;
} catch (IOException e) {
    e.printStackTrace();
    return false;
...