This Java tip demonstrates a method of copying one file to another file. Developer may use file streams to copy the contents of the file.

  // Copy the source file to target file.
    // In case the dst file does not exist, it is created
    void copy(File source, File target) throws IOException {

        InputStream in = new FileInputStream(source);
        OutputStream out = new FileOutputStream(target);
        // Copy the bits from instream to outstream
        byte[] buf = new byte[1024];
        int len;

        while ((len = > 0) {
            out.write(buf, 0, len);