Here you can find the source of writeStringToFile(String content, String encoding, String fileName)
public static void writeStringToFile(String content, String encoding, String fileName) throws IOException, UnsupportedEncodingException
//package com.java2s; /*//from www.j a va 2s .c o m * {{{ header & license * GeneralUtil.java * Copyright (c) 2004, 2005 Patrick Wright * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License * as published by the Free Software Foundation; either version 2.1 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * }}} */ import java.io.*; public class Main { public static void writeStringToFile(String content, String encoding, String fileName) throws IOException, UnsupportedEncodingException { File f = new File(fileName); FileOutputStream fos = new FileOutputStream(f); OutputStreamWriter osw = new OutputStreamWriter(fos, encoding); BufferedWriter bw = new BufferedWriter(osw); PrintWriter pw = new PrintWriter(bw); pw.print(content); pw.flush(); bw.flush(); fos.close(); System.out.println("Wrote file: " + f.getAbsolutePath()); } }