Java FileInputStream Copy copyFile(final String sSource, final String sDest)

Here you can find the source of copyFile(final String sSource, final String sDest)

Description

Copy the file contents.

License

LGPL

Parameter

Parameter Description
sSource a parameter
sDest a parameter

Return

true if everything went ok, false if there was a problem

Declaration

public static final boolean copyFile(final String sSource, final String sDest) 

Method Source Code

//package com.java2s;
//License from project: LGPL 

import java.io.FileInputStream;
import java.io.FileOutputStream;

import java.io.InputStream;
import java.io.OutputStream;

public class Main {
    /**// w  ww .jav  a2  s.  co  m
     * Copy the file contents.
     * 
     * @param sSource
     * @param sDest
     * @return true if everything went ok, false if there was a problem
     */
    public static final boolean copyFile(final String sSource, final String sDest) {
        InputStream is = null;
        OutputStream os = null;

        try {
            is = new FileInputStream(sSource);
            os = new FileOutputStream(sDest);

            final byte[] buff = new byte[16 * 1024];
            int len;

            while ((len = is.read(buff)) > 0) {
                os.write(buff, 0, len);
            }

            os.flush();
            os.close();
            os = null;

            is.close();
            is = null;

            return true;
        } catch (final Throwable t) {
            return false;
        } finally {
            if (is != null) {
                try {
                    is.close();
                } catch (final Exception e) {
                    // improbable, ignore
                }
            }

            if (os != null) {
                try {
                    os.close();
                } catch (final Exception e) {
                    // improbable, ignore
                }
            }
        }
    }
}

Related

  1. copyFile(final File srcPath, final File dstPath)
  2. copyFile(final InputStream in, final File destFile)
  3. copyFile(final String from, final String to)
  4. copyFile(final String sourceFile, final String destinationFile)
  5. copyFile(final String sourceFilePath, final String destFilePath)
  6. copyFile(InputStream in, File dst)
  7. copyFile(InputStream in, File to)
  8. copyFile(InputStream in, String destFile)
  9. copyFile(OutputStream out, InputStream in)