Here you can find the source of saveToLocal(InputStream in, String filePath)
public static void saveToLocal(InputStream in, String filePath)
//package com.java2s; import java.io.DataOutputStream; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; public class Main { public static void saveToLocal(InputStream in, String filePath) { try {/*from ww w . j a v a 2s . c o m*/ File file = new File(filePath); if (!file.exists() && !file.isDirectory()) { file.createNewFile(); } DataOutputStream out = new DataOutputStream( new FileOutputStream(new File(file.getAbsolutePath()))); byte[] dataByte = new byte[in.available()]; in.read(dataByte); for (int i = 0; i < dataByte.length; i++) out.write(dataByte[i]); out.flush(); out.close(); in.close(); } catch (IOException e) { e.printStackTrace(); } } }