Here you can find the source of saveFile(File file, String fileName, String filesDirectory)
public static void saveFile(File file, String fileName, String filesDirectory) throws IOException
//package com.java2s; //License from project: Open Source License import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; public class Main { public static void saveFile(File file, String fileName, String filesDirectory) throws IOException { FileInputStream in = null; FileOutputStream out = null; File dir = new File(filesDirectory); if (!dir.exists()) dir.mkdirs();//from w w w. j av a2 s . c o m String targetPath = dir.getPath() + File.separator + fileName; System.out.println("source file path ::" + file.getAbsolutePath()); System.out.println("saving file to ::" + targetPath); File destinationFile = new File(targetPath); try { in = new FileInputStream(file); out = new FileOutputStream(destinationFile); int c; while ((c = in.read()) != -1) { out.write(c); } } finally { if (in != null) { in.close(); } if (out != null) { out.close(); } } } }