Java FileInputStream Copy copyFile(String fileInName, String fileOutName)

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

Description

copy File

License

Open Source License

Declaration


static public boolean copyFile(String fileInName, String fileOutName) 

Method Source Code

//package com.java2s;
/*/*from  w w w.j a v a 2s . c om*/
 * ISABEL: A group collaboration tool for the Internet
 * Copyright (C) 2009 Agora System S.A.
 * 
 * This file is part of Isabel.
 * 
 * Isabel is free software: you can redistribute it and/or modify
 * it under the terms of the Affero GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * Isabel 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
 * Affero GNU General Public License for more details.
 * 
 * You should have received a copy of the Affero GNU General Public License
 * along with Isabel.  If not, see <http://www.gnu.org/licenses/>.
 */

import java.io.*;

public class Main {

    static public boolean copyFile(String fileInName, String fileOutName) {

        try {

            FileInputStream in = new FileInputStream(fileInName);

            FileOutputStream out = new FileOutputStream(fileOutName);

            byte buffer[] = new byte[16];

            int n;

            while ((n = in.read(buffer)) > -1)

                out.write(buffer, 0, n);

            out.close();

            in.close();

            return true;

        } catch (Exception e) {

            return false;

        }

    }

    static public boolean copyFile(String fileInName, OutputStream out) {

        try {

            FileInputStream in = new FileInputStream(fileInName);

            byte buffer[] = new byte[16];

            int n;

            while ((n = in.read(buffer)) > -1)

                out.write(buffer, 0, n);

            out.close();

            in.close();

            return true;

        } catch (Exception e) {

            return false;

        }

    }
}

Related

  1. copyFile(InputStream in, File to)
  2. copyFile(InputStream in, String destFile)
  3. copyFile(OutputStream out, InputStream in)
  4. copyFile(String f1, String f2)
  5. copyFile(String fileIn, String fileOut)
  6. copyFile(String fileName, String fromDir, String toDir)
  7. copyFile(String fileOutPut, String fileIn)
  8. copyFile(String from, String to)
  9. copyFile(String fromFile, String toFile)