Here you can find the source of saveToDisk(String contents, String filename)
public static void saveToDisk(String contents, String filename) throws IOException
//package com.java2s; //License from project: Open Source License import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; public class Main { public static String DEFAULT_CHARSET = "UTF-8"; public static void saveToDisk(String contents, String filename) throws IOException { FileOutputStream fos = null; try {// w ww . ja va 2 s. co m fos = new FileOutputStream(filename); fos.write(contents.getBytes(DEFAULT_CHARSET)); fos.flush(); } finally { if (fos != null) fos.close(); } } /** * save primary conetent to local * @param is * @param filename * @throws FileNotFoundException * @throws IOException */ public static void saveToDisk(InputStream is, String filename) throws FileNotFoundException, IOException { FileOutputStream fos = new FileOutputStream(filename); byte[] buf = new byte[1024]; int len = 0; while ((len = is.read(buf)) > 0) { fos.write(buf, 0, len); } fos.flush(); fos.close(); } }