Here you can find the source of copyFile(String orig, String dest)
public static void copyFile(String orig, String dest)
//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(); } }