Here you can find the source of writeFile(String path, String content)
public static String writeFile(String path, String content) throws IOException
//package com.java2s; //License from project: Apache License import java.io.BufferedOutputStream; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStream; public class Main { public static String writeFile(String path, String content) throws IOException { byte[] matter = content.getBytes("GBK"); return writeFile(path, matter, false); }// w w w.j a v a2s.c om public static String writeFile(String path, String content, boolean append) throws IOException { byte[] matter = content.getBytes("GBK"); return writeFile(path, matter, append); } public static String writeFile(String path, byte[] content) throws IOException { return writeFile(path, content, false); } public static String writeFile(String path, byte[] content, boolean append) throws IOException { if (path == null || path.length() == 0) { path = File.createTempFile("writeServerFile", ".file").getAbsolutePath(); } else { path = new File(path).getAbsolutePath(); } OutputStream os = null; try { os = new BufferedOutputStream(new FileOutputStream(path, append)); os.write(content); os.flush(); } finally { if (os != null) { os.close(); } } return path; } }