Java FileInputStream Copy copyFile(String source, String destination)

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

Description

copy File

License

Open Source License

Declaration

private static boolean copyFile(String source, String destination) 

Method Source Code

//package com.java2s;
/******************************************************************
 *
 * Copyright 2018 Samsung Electronics All Rights Reserved.
 *
 *
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.//from   w  w  w .  j  a v  a  2s  . c  o  m
 *
 *
 ******************************************************************/

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.FileNotFoundException;
import java.io.InputStream;

import java.io.OutputStream;

public class Main {
    private static boolean copyFile(String source, String destination) {
        InputStream inStream = null;
        OutputStream outStream = null;
        boolean isSucceed = false;
        try {
            File desFile = new File(destination);
            File srcFile = new File(source);

            inStream = new FileInputStream(srcFile);
            outStream = new FileOutputStream(desFile);
            byte[] buffer = new byte[1024];

            int length;
            while ((length = inStream.read(buffer)) > 0) {
                outStream.write(buffer, 0, length);
            }
            isSucceed = true;
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                if (inStream != null)
                    inStream.close();
                if (outStream != null)
                    outStream.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return isSucceed;
    }
}

Related

  1. copyFile(String pathOrig, String pathDst)
  2. copyFile(String quelle, String ziel)
  3. copyFile(String resourceFimeName, String targetFileName)
  4. copyFile(String s, String s1)
  5. copyFile(String source, String dest)
  6. copyFile(String source, String destination)
  7. copyFile(String source, String destination)
  8. copyFile(String source, String destination)
  9. copyFile(String source, String target)