Java tutorial
//package com.java2s; //it under the terms of the GNU Affero General Public License as published by import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; public class Main { /** * Copys a document file from one directory to another * @param documentPath * @param destPath * @param filename * @param entityId src file Entity ID * @param newEntityId dest file Entity ID * @throws IOException */ public static void copyDocumentFile(File documentDir, File destDir, String filename, Object entityId, Object newEntityId) throws IOException { File src = new File(documentDir, filename); File dest = new File(destDir, filename); if (dest.exists()) dest.delete(); byte[] buffer = new byte[4096]; int read = 0; InputStream in = null; OutputStream out = null; try { in = new BufferedInputStream(new FileInputStream(src)); out = new BufferedOutputStream(new FileOutputStream(dest)); while (true) { read = in.read(buffer); if (read == -1) { // -1 bedeutet EOF break; } out.write(buffer, 0, read); } } finally { if (in != null) { try { in.close(); } finally { if (out != null) { out.close(); } } } } } }