Java Utililty Methods File Copy

List of utility methods to do File Copy

Description

The list of methods to do File Copy are organized into topic(s).

Method

voiddoCopyFile(File srcFile, File destFile, boolean preserveFileDate)
do Copy File
if (destFile.exists() && destFile.isDirectory()) {
    throw new IOException("Destination '" + destFile + "' exists but is a directory");
FileInputStream input = new FileInputStream(srcFile);
try {
    FileOutputStream output = new FileOutputStream(destFile);
    try {
        copy(input, output);
...
voidfileCopy(File source, String dest)
file Copy
final File newFile = new File(dest);
final byte[] buffer = new byte[4096];
final FileInputStream inputStream = new FileInputStream(source);
final FileOutputStream outputStream = new FileOutputStream(newFile);
int len;
while ((len = inputStream.read(buffer)) != -1) {
    outputStream.write(buffer, 0, len);
inputStream.close();
outputStream.close();
voidfileCopy(File srcFile, File tarFile)
file Copy
FileInputStream is = null;
FileOutputStream os = null;
try {
    is = new FileInputStream(srcFile);
    os = new FileOutputStream(tarFile);
    int bytesRead = 0;
    byte[] buffer = new byte[8192];
    while ((bytesRead = is.read(buffer, 0, 8192)) != -1) {
...
voidFileCopy(InputStream input, OutputStream output, int bufferSize)
File Copy
byte[] buf = new byte[bufferSize];
int n = input.read(buf);
while (n >= 0) {
    output.write(buf, 0, n);
    n = input.read(buf);
output.flush();
voidfileCopy(String from, String to)
Copy a file.
fileThing(from, to, false);
voidfileCopy(String from, String to)

file copy

FileInputStream fis = null;
FileOutputStream fos = null;
try {
    fis = new FileInputStream(from);
    fos = new FileOutputStream(to);
    final int BUFSIZ = 1024;
    byte buf[] = new byte[BUFSIZ];
    int len = 0;
...
voidfileCopy(String fromPath, String toPath)
file Copy
File inputFile = new File(fromPath);
File outputFile = new File(toPath);
FileReader in = new FileReader(inputFile);
FileWriter out = new FileWriter(outputFile);
int c;
while ((c = in.read()) != -1)
    out.write(c);
in.close();
...
booleanfileCopy(String oldFilePath, String newFilePath, boolean isCover)
file Copy
if (!checkFile(oldFilePath, false)) {
    return false;
if (checkFile(newFilePath, true) && (!isCover)) {
    return false;
FileInputStream in = null;
FileOutputStream out = null;
...
voidfileCopy(String sFrom, String sTo)
file Copy
File f1 = new File(sFrom);
File f2 = new File(sTo);
InputStream in = new FileInputStream(f1);
OutputStream out = new FileOutputStream(f2);
byte[] buf = new byte[1024];
int len;
while ((len = in.read(buf)) > 0) {
    out.write(buf, 0, len);
...
voidfileCopy(String source, String target)
file Copy
try (InputStream in = new FileInputStream(source)) {
    try (OutputStream out = new FileOutputStream(target)) {
        byte[] buffer = new byte[4096];
        int bytesToRead;
        while ((bytesToRead = in.read(buffer)) != -1) {
            out.write(buffer, 0, bytesToRead);