Here you can find the source of save(String fileContent, File file, String encoding)
Parameter | Description |
---|---|
fileContent | - the file content string |
file | - the target file |
encoding | - the text encoding |
Parameter | Description |
---|---|
IOException | an exception |
public static void save(String fileContent, File file, String encoding) throws IOException
//package com.java2s; /*// w w w. ja v a2 s .c o m * This file is part of Pustefix. * * Pustefix 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 of the License, or * (at your option) any later version. * * Pustefix 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 Pustefix; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStreamWriter; public class Main { /** * Saves a string to a text file. * * @param fileContent - the file content string * @param file - the target file * @param encoding - the text encoding * @throws IOException */ public static void save(String fileContent, File file, String encoding) throws IOException { FileOutputStream fos = new FileOutputStream(file); OutputStreamWriter writer = new OutputStreamWriter(fos, encoding); try { writer.write(fileContent); writer.flush(); } finally { fos.close(); } } }