Java Utililty Methods FileInputStream Copy

List of utility methods to do FileInputStream Copy

Description

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

Method

voidcopyFile(File sourceFile, String newFileName)
copy File
File newFile = new File(newFileName);
copyFile(sourceFile, newFile);
voidcopyFile(File sourceLocation, File targetLocation)
copy File
if (sourceLocation.isDirectory()) {
    throw new IOException("File is a directory, not a file, cannot copy");
} else {
    InputStream in = new FileInputStream(sourceLocation);
    OutputStream out = new FileOutputStream(targetLocation);
    byte[] buf = new byte[1024];
    int len;
    while ((len = in.read(buf)) > 0) {
...
voidcopyFile(File src, File dest)
copy File
FileInputStream fileSrc = new FileInputStream(src);
FileOutputStream fileDest = new FileOutputStream(dest);
copyInputStream(fileSrc, fileDest);
voidcopyFile(File src, File dest)
copy File
try {
    copy(new FileInputStream(src), new FileOutputStream(dest));
} catch (IOException e) {
    e.printStackTrace();
booleancopyFile(File src, File dest)
Copy a file to another location.
try {
    InputStream in = new FileInputStream(src);
    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) {
    e.printStackTrace();
    return false;
} catch (IOException e) {
    e.printStackTrace();
    return false;
return true;
voidcopyFile(File src, File dest)
copy File
if (src == null || (!src.exists()) || dest == null || dest.isDirectory()) {
    return;
byte[] buf = new byte[4096];
OutputStream out = null;
FileInputStream in = null;
try {
    out = new FileOutputStream(dest);
...
voidcopyFile(File src, File dest)
Copies src File to dest directory (preserve's src filename: src.getName()), using Input/Output streams.
FileInputStream in = new FileInputStream(src);
if (dest.isDirectory())
    dest = new File(dest, src.getName());
FileOutputStream out = new FileOutputStream(dest);
copyInputStream(in, out);
in.close();
out.close();
voidcopyFile(File src, File dest)
Copy file from src (path to the original file) to dest (path to the destination file).
InputStream in = null;
OutputStream out = null;
byte[] buffer = new byte[12 * 1024];
int read;
try {
    in = new FileInputStream(src);
    try {
        out = new FileOutputStream(dest);
...
voidcopyFile(File src, File dest)
copy File
byte[] bytes = readFile(src);
createFile(bytes, dest);
voidcopyFile(File src, File dest)
Copies a file.
if (src.exists() && !src.isDirectory()) {
    InputStream in = new FileInputStream(src);
    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();