Here you can find the source of InputStream2File(InputStream in, String filePath)
public static String InputStream2File(InputStream in, String filePath)
//package com.java2s; import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; public class Main { public static String InputStream2File(InputStream in, String filePath) { FileOutputStream fos = null; String fileName = filePath + File.separator + System.currentTimeMillis() + ".jpg"; try {// ww w . j a va2s. co m int flag = 0; fos = new FileOutputStream(fileName); byte[] b = new byte[1024]; while ((flag = in.read(b, 0, 1024)) != -1) { fos.write(b, 0, flag); } } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { try { in.close(); fos.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } return fileName; } }