Here you can find the source of saveFile(String pathRoot, String subPath, boolean isFoler, InputStream in)
public static void saveFile(String pathRoot, String subPath, boolean isFoler, InputStream in)
//package com.java2s; import java.io.File; import java.io.FileOutputStream; import java.io.InputStream; public class Main { public static void saveFile(String pathRoot, String subPath, boolean isFoler, InputStream in) { FileOutputStream fos = null; File file = new File(pathRoot + File.separator + subPath); if (file.getParentFile().exists() == false) { file.getParentFile().mkdirs(); }/*from w w w . ja v a 2 s .c o m*/ if (isFoler) { if (file.exists() == false) { file.mkdirs(); } return; } byte[] buffer = new byte[2048]; int len; try { if (file.exists()) { file.delete(); } fos = new FileOutputStream(file); while ((len = in.read(buffer)) != -1) { fos.write(buffer, 0, len); } fos.close(); } catch (Exception e) { throw new RuntimeException(e); } finally { try { if (fos != null) fos.close(); } catch (Exception e1) { e1.printStackTrace(); } } } }