Here you can find the source of writeFile(String filename, String content)
Parameter | Description |
---|---|
filename | file to create or overwrite. |
content | content to write. |
public static File writeFile(String filename, String content)
//package com.java2s; //License from project: Apache License import java.io.*; public class Main { private static final String FILE_ENCODING = "UTF-8"; /**/*w ww . j a v a2 s.co m*/ * Writes content to file, in UTF-8 encoding. * * @param filename file to create or overwrite. * @param content content to write. * @return file reference to file. */ public static File writeFile(String filename, String content) { PrintWriter pw = null; try { pw = new PrintWriter(filename, FILE_ENCODING); pw.write(content); pw.flush(); } catch (FileNotFoundException e) { throw new IllegalArgumentException("Unable to write to: " + filename, e); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); } finally { if (pw != null) { pw.close(); } } return new File(filename); } }