Here you can find the source of saveFile(Context context, String fileName, InputStream inputStream)
public static boolean saveFile(Context context, String fileName, InputStream inputStream)
//package com.java2s; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import android.content.Context; public class Main { public static boolean saveFile(Context context, String fileName, InputStream inputStream) { File cacheDir = context.getCacheDir(); File outputFile = new File(cacheDir, fileName); writeFile(outputFile, inputStream); return true; }/*from w ww . ja va 2s .c o m*/ public static void writeFile(File outputFile, InputStream inputStream) { try { // write the inputStream to a FileOutputStream OutputStream out = new FileOutputStream(outputFile); int read = 0; byte[] bytes = new byte[1024]; while ((read = inputStream.read(bytes)) != -1) { out.write(bytes, 0, read); } out.flush(); out.close(); } catch (IOException e) { System.out.println(e.getMessage()); } } }