Here you can find the source of copyFile(String sourceFileName, String targetFileName)
Parameter | Description |
---|---|
sourceFileName | file name of the file to be copied |
targetFileName | file name where to copy the file |
public static void copyFile(String sourceFileName, String targetFileName)
//package com.java2s; //License from project: Open Source License import java.io.File; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class Main { /**/*from w w w. ja v a 2 s. co m*/ * Copies a file to the given target. * * @param sourceFileName * file name of the file to be copied * @param targetFileName * file name where to copy the file */ public static void copyFile(String sourceFileName, String targetFileName) { final File inputFile = new File(sourceFileName); final File outputFile = new File(targetFileName); try { final FileReader in = new FileReader(inputFile); final FileWriter out = new FileWriter(outputFile); int c; while ((c = in.read()) != -1) { out.write(c); } in.close(); out.close(); } catch (final FileNotFoundException e) { e.printStackTrace(); } catch (final IOException e) { e.printStackTrace(); } } }