Here you can find the source of writeFileContent(File file, String content)
Parameter | Description |
---|---|
file | File to write String content to. |
Parameter | Description |
---|---|
IOException | an exception |
public static void writeFileContent(File file, String content) throws IOException
//package com.java2s; /** /* www. j a v a 2 s .c om*/ This class is part of the Java Tools (see http://mpii.de/yago-naga/javatools). It is licensed under the Creative Commons Attribution License (see http://creativecommons.org/licenses/by/3.0) by the YAGO-NAGA team (see http://mpii.de/yago-naga) Some utility methods for arrays */ import java.io.BufferedWriter; import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStreamWriter; import java.nio.charset.Charset; public class Main { /** * Writes the content of the string to the (UTF-8 encoded) file. * * @param file File to write String content to. * @return Content of file. * @throws IOException */ public static void writeFileContent(File file, String content) throws IOException { BufferedWriter writer = getBufferedUTF8Writer(file); writer.write(content); writer.flush(); writer.close(); } /** * Creates a BufferedWriter for UTF-8-encoded files * * @param file File in UTF-8 encoding * @return BufferedWriter for file * @throws FileNotFoundException */ public static BufferedWriter getBufferedUTF8Writer(File file) throws FileNotFoundException { return new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), Charset.forName("UTF-8"))); } /** * Creates a BufferedWriter for UTF-8-encoded files * * @param fileName Path to file in UTF-8 encoding * @return BufferedWriter for file * @throws FileNotFoundException */ public static BufferedWriter getBufferedUTF8Writer(String fileName) throws FileNotFoundException { return new BufferedWriter(new OutputStreamWriter(new FileOutputStream(fileName), Charset.forName("UTF-8"))); } }