Helper function to write UTF-8 files - Java File Path IO

Java examples for File Path IO:UTF

Description

Helper function to write UTF-8 files

Demo Code


//package com.java2s;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;

public class Main {
    /**/*  w w  w.  j  ava  2s . c  o  m*/
     * Helper function to write files
     *
     * @param FileName
     *            The file to write to
     * @param content
     *            Content to write in the file
     */
    public static void printFile(String FileName, String content) {
        PrintWriter writer;
        try {
            writer = new PrintWriter(FileName, "UTF-8");
            writer.print(content);
            writer.close();
        } catch (FileNotFoundException | UnsupportedEncodingException e) {
            e.printStackTrace();
        }
    }
}

Related Tutorials