Java BufferedReader Copy copyFile(String orig, String dest)

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

Description

copy File

License

Open Source License

Declaration

public static void copyFile(String orig, String dest) 

Method Source Code

//package com.java2s;
/*/*from   w w w  .  j  a v  a  2  s. c o  m*/
 * Copyright 2010
 * IBB-CEB - Institute for Biotechnology and Bioengineering - Centre of Biological Engineering
 * CCTC - Computer Science and Technology Center
 *
 * University of Minho 
 * 
 * This is free software: you can redistribute it and/or modify 
 * it under the terms of the GNU Public License as published by 
 * the Free Software Foundation, either version 3 of the License, or 
 * (at your option) any later version. 
 * 
 * This code 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 Public License for more details. 
 * 
 * You should have received a copy of the GNU Public License 
 * along with this code. If not, see http://www.gnu.org/licenses/ 
 * 
 * Created inside the SysBioPseg Research Group (http://sysbio.di.uminho.pt)
 */

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;

import java.io.IOException;
import java.io.InputStream;

import java.io.OutputStream;

public class Main {
    public static void copyFile(String orig, String dest) {
        copyFile(new File(orig), new File(dest));
    }

    public static void copyFile(File orig, File dest) {

        InputStream in;
        try {
            in = new FileInputStream(orig);

            OutputStream out = new FileOutputStream(dest);
            byte[] buf = new byte[1024];
            int len;
            while ((len = in.read(buf)) > 0) {
                out.write(buf, 0, len);
            }
            in.close();
            out.close();
        } catch (FileNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

    public static String read(String filePath) throws IOException {
        FileReader fr = new FileReader(filePath);
        BufferedReader br = new BufferedReader(fr);
        StringBuilder sb = new StringBuilder();
        String line;
        try {
            while ((line = br.readLine()) != null)
                sb.append(line + "\n");
        } finally {
            br.close();
            fr.close();
        }
        return sb.toString();
    }
}

Related

  1. copyFile(File from, File to)
  2. copyFile(File orgFile, File dstFile)
  3. copyFile(File original, File copy)
  4. copyFile(File source, File dest)
  5. copyFile(File src, File dst)
  6. copyFile(String source, String dest)
  7. copyFile(String src, String dst)
  8. copyFile(String src, String dst)
  9. copyFile(String srcFile, String dstFile)