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

booleancopyFile(final File src, final File dst)
copy File
if (src.length() == 0) {
    return touch(dst);
InputStream is = null;
FileOutputStream os = null;
try {
    try {
        is = new FileInputStream(src);
...
voidcopyFile(final File srcFile, final File destFile)
This method copies the src file to dest file.
InputStream input = null;
input = new FileInputStream(srcFile);
File parentFile = destFile.getParentFile();
if ((null != parentFile) && (!parentFile.exists()) && (!parentFile.mkdirs())) {
    if (null != input) {
        input.close();
    throw new IOException("Destination '" + destFile + "' parent directory cannot be created");
...
voidcopyFile(final File srcPath, final File dstPath)
copy File
if (srcPath.isDirectory()) {
    if (!dstPath.exists()) {
        dstPath.mkdir();
    String[] files = srcPath.list();
    for (String file : files) {
        copyFile(new File(srcPath, file), new File(dstPath, file));
} else {
    if (!srcPath.exists()) {
        throw new IOException("Directory Not Found ::: " + srcPath);
    } else {
        InputStream in = null;
        OutputStream out = null;
        try {
            if (!dstPath.getParentFile().exists()) {
                dstPath.getParentFile().mkdirs();
            in = new FileInputStream(srcPath);
            out = new FileOutputStream(dstPath);
            byte[] buf = new byte[1024];
            int len;
            while ((len = in.read(buf)) > 0) {
                out.write(buf, 0, len);
        } finally {
            if (in != null) {
                try {
                    in.close();
                } catch (Exception e) {
                    e.printStackTrace();
            if (out != null) {
                try {
                    out.close();
                } catch (Exception e) {
                    e.printStackTrace();
voidcopyFile(final InputStream in, final File destFile)
Copy a file.
if (destFile.exists() && destFile.isFile()) {
    destFile.delete();
FileOutputStream out = null;
try {
    out = new FileOutputStream(destFile);
    copyFile(in, out);
} finally {
...
voidcopyFile(final String from, final String to)
Copy file 'from' to file 'to' If not successful, exception is thrown
byte[] daten = readFile(from);
writeFile(to, daten);
voidcopyFile(final String sourceFile, final String destinationFile)
This does a binary file copy
final FileInputStream fis = new FileInputStream(sourceFile);
final FileOutputStream fos = new FileOutputStream(destinationFile);
try {
    final byte[] buffer = new byte[4096];
    int numBytesRead;
    do {
        numBytesRead = fis.read(buffer);
        if (numBytesRead > 0) {
...
voidcopyFile(final String sourceFilePath, final String destFilePath)
copy File
final File sourceFile = new File(sourceFilePath);
final File destFile = new File(destFilePath);
if (!destFile.exists()) {
    destFile.createNewFile();
} else {
    destFile.delete();
    destFile.createNewFile();
FileInputStream source = null;
FileOutputStream destination = null;
try {
    source = new FileInputStream(sourceFile);
    destination = new FileOutputStream(destFile);
    long count = 0;
    final long size = source.getChannel().size();
    while ((count += destination.getChannel().transferFrom(source.getChannel(), count,
            size - count)) < size) {
        ;
} finally {
    if (source != null) {
        source.close();
    if (destination != null) {
        destination.close();
booleancopyFile(final String sSource, final String sDest)
Copy the file contents.
InputStream is = null;
OutputStream os = null;
try {
    is = new FileInputStream(sSource);
    os = new FileOutputStream(sDest);
    final byte[] buff = new byte[16 * 1024];
    int len;
    while ((len = is.read(buff)) > 0) {
...
voidcopyFile(InputStream in, File dst)
Copies the source file to destination file.
OutputStream out = new FileOutputStream(dst);
byte[] buf = new byte[1024];
int len;
while ((len = in.read(buf)) > 0) {
    out.write(buf, 0, len);
in.close();
out.close();
...
voidcopyFile(InputStream in, File to)
Copy from an input stream to a file
FileOutputStream out = new FileOutputStream(to);
int len;
byte[] buffer = new byte[4096];
while ((len = in.read(buffer)) != -1) {
    out.write(buffer, 0, len);
out.close();
in.close();
...