Here you can find the source of writer(String path, String content, String charset)
public static void writer(String path, String content, String charset) throws IOException
//package com.java2s; //License from project: Open Source License import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.Reader; import java.io.Writer; import java.net.ServerSocket; import java.net.Socket; import java.nio.channels.Channel; public class Main { public static void writer(String path, byte[] b) throws IOException { writer(path, b, false);//from www . j ava2s. c om } public static void writer(String path, byte[] b, boolean isAppend) throws IOException { OutputStream out = fileOut(path, isAppend); out.write(b); close(out); } public static void writer(String path, String content) throws IOException { writer(path, content, "UTF-8"); } public static void writer(String path, String content, String charset) throws IOException { OutputStream out = fileOut(path, false); out.write(content.getBytes(charset)); close(out); } public static OutputStream fileOut(String path, boolean append) throws FileNotFoundException { return fileOut(new File(path), append); } public static OutputStream fileOut(File file, boolean append) throws FileNotFoundException { if (!file.exists()) { try { file.createNewFile(); } catch (IOException e) { e.printStackTrace(); } } return new FileOutputStream(file, append); } public static void close(InputStream in) { if (null != in) { try { in.close(); } catch (IOException e) { e.printStackTrace(); } } } public static void close(Socket socket) { if (null != socket) { if (!socket.isClosed()) { try { socket.close(); } catch (IOException e) { e.printStackTrace(); } } } } public static void close(ServerSocket socket) { if (null != socket) { if (!socket.isClosed()) { try { socket.close(); } catch (IOException e) { e.printStackTrace(); } } } } public static void close(OutputStream out) { if (null != out) { try { out.close(); } catch (IOException e) { e.printStackTrace(); } } } public static void close(Reader reader) { if (null != reader) { try { reader.close(); } catch (IOException e) { e.printStackTrace(); } } } public static void close(Writer writer) { if (null != writer) { try { writer.close(); } catch (IOException e) { e.printStackTrace(); } } } public static void close(Channel channel) { if (null != channel) { if (channel.isOpen()) { try { channel.close(); } catch (IOException e) { e.printStackTrace(); } } } } }