Here you can find the source of copyFileToTemp(InputStream is, String dirName, String fileName)
public static File copyFileToTemp(InputStream is, String dirName, String fileName)
//package com.java2s; import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.File; import java.io.FileOutputStream; import java.io.InputStream; public class Main { public static File copyFileToTemp(InputStream is, String dirName, String fileName) { File path = new File(System.getProperty("java.io.tmpdir") + "/" + dirName); File outputfile = new File(path + "/" + fileName); try {// w ww. ja va2 s .c om if (path.exists() == false) { path.mkdir(); } if (outputfile.exists() == false) { outputfile.createNewFile(); } BufferedInputStream bis = new BufferedInputStream(is); BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(outputfile)); int FILE_CHUNK_SIZE = 10000; byte[] bytearray = new byte[FILE_CHUNK_SIZE]; int count = 0; while ((count = bis.read(bytearray, 0, FILE_CHUNK_SIZE)) != -1) { bos.write(bytearray, 0, count); } bos.flush(); bos.close(); } catch (Exception e) { e.printStackTrace(); // TODO error msg return null; } return outputfile; } }