Android File Copy copyFile(String source, String dest)

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

Description

copy File

License

Open Source License

Declaration

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

Method Source Code

//package com.java2s;
/*//from  ww  w. jav a2  s . c  om
 Copyright (C) 2010 Haowen Ning

 This program is free software; you can redistribute it and/or
 modify it under the terms of the GNU General Public License
 as published by the Free Software Foundation; either version 2
 of the License, or (at your option) any later version.

 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

 See the GNU General Public License for more details.

 You should have received a copy of the GNU General Public License
 along with this program; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

 */

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

public class Main {
    public static void copyFile(String source, String dest)
            throws IOException {
        File sourceFile = new File(source);
        File destFile = new File(dest);

        destFile.createNewFile();
        InputStream in = new FileInputStream(sourceFile);
        OutputStream out = new FileOutputStream(destFile);

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

Related

  1. CopyCacheFile(Context con, String assetsFile)
  2. CopyFile(Context con, String assetsFile)
  3. copyFile(File from, File to)
  4. copyFile(File from, File to)
  5. copyFile(File sourceFile, File targetFile)