Here you can find the source of copyFilesBinary(String srcFile, String destDir)
Parameter | Description |
---|---|
originalFile | source file location |
toLocation | destination dir |
Parameter | Description |
---|---|
IOException | exception |
public static void copyFilesBinary(String srcFile, String destDir) throws IOException
//package com.java2s; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; public class Main { /**/* w w w. j ava2 s . c o m*/ * Copies binary file originalFile to location toLocation * If destination file exists it does nothing * * @param originalFile source file location * @param toLocation destination dir * @throws IOException exception */ public static void copyFilesBinary(String srcFile, String destDir) throws IOException { File originalFile = new File(srcFile); File toLocation = new File(destDir); File destFile = new File(toLocation.getAbsolutePath() + File.separator + originalFile.getName()); if (destFile.exists()) return; FileInputStream fis = null; FileOutputStream fos = null; try { fis = new FileInputStream(originalFile); fos = new FileOutputStream(new File(toLocation, originalFile.getName())); byte[] buffer = new byte[4096]; int bytesRead; while ((bytesRead = fis.read(buffer)) != -1) { fos.write(buffer, 0, bytesRead); // write } } finally { if (fis != null) { try { fis.close(); } catch (IOException e) { // do nothing } } if (fos != null) { try { fos.flush(); fos.close(); } catch (IOException e) { // do nothing } } } } }