Java FileInputStream Copy copyFile(String src, String dest)

Here you can find the source of copyFile(String src, String dest)

Description

modelled on example from http://javaalmanac.com/, which says "All the code examples from the book are made available here for you to copy and paste into your programs."

License

Open Source License

Declaration

static public void copyFile(String src, String dest) throws IOException 

Method Source Code

//package com.java2s;
// This software is published under the terms of the MIT license, a copy

import java.io.*;

public class Main {
    /** modelled on example from http://javaalmanac.com/, which says
      "All the code examples from the book are made available here for you to copy and paste into your programs." */
    static public void copyFile(String src, String dest) throws IOException {
        if (!new File(src).exists()) {
            return;
        }//from w  ww . ja v  a 2 s  . co  m
        InputStream in = new FileInputStream(src);
        OutputStream out = new FileOutputStream(dest);

        byte[] buf = new byte[1024];
        int len;
        while ((len = in.read(buf)) > 0) {
            out.write(buf, 0, len);
        }
        in.close();
        out.close();
    }
}

Related

  1. copyFile(String sourceFilePath, String destinationFilePath)
  2. copyFile(String sourcePath, String newPath)
  3. copyFile(String src, File dest)
  4. copyFile(String src, String dest)
  5. copyFile(String src, String dest)
  6. copyFile(String src, String dest)
  7. copyFile(String src, String dest)
  8. copyFile(String src, String dst)
  9. copyFile(String src, String dst)