Here you can find the source of copyFile(String srcFile, String dstFile)
Parameter | Description |
---|---|
srcFile | a parameter |
dstFile | a parameter |
public static void copyFile(String srcFile, String dstFile)
//package com.java2s; //License from project: Academic Free License import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.InputStream; import java.io.OutputStream; import java.io.Reader; import java.io.Writer; public class Main { /**/*from w w w . j av a 2 s . co m*/ * Copy the contents of the first file to the second file. * * @param srcFile * @param dstFile */ public static void copyFile(String srcFile, String dstFile) { FileInputStream fis = null; FileOutputStream fos = null; byte ba[] = new byte[10240]; int numRead = 0; try { fis = new FileInputStream(srcFile); fos = new FileOutputStream(dstFile); numRead = fis.read(ba); while (numRead > 0) { fos.write(ba, 0, numRead); numRead = fis.read(ba); } fos.flush(); } catch (Exception ex) { ex.printStackTrace(); } finally { close(fis); close(fos); } } /** * Close the output stream and trap any exceptions. */ public static void close(OutputStream os) { if (os != null) { try { os.close(); } catch (Exception ex) { } } } public static void close(Writer fw) { if (fw != null) { try { fw.close(); } catch (Exception ex) { } ; } } /** * Close the input stream and trap any exceptions. */ public static void close(InputStream is) { if (is != null) { try { is.close(); } catch (Exception ex) { } } } /** * Close the reader. * * @param r */ public static void close(Reader r) { if (r != null) { try { r.close(); } catch (Exception ex) { } } } }