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(File file, File newFile, boolean overwrite, boolean setLastModified)
Copies the content of a file to another file.
if (newFile.exists() && !overwrite) {
    return false;
FileInputStream fis = null;
try {
    fis = new FileInputStream(file);
    copyStream(fis, new FileOutputStream(newFile), true);
    if (setLastModified) {
...
voidcopyFile(File file, OutputStream os)
copy File
final int buffersize = 4096;
FileInputStream fis = new FileInputStream(file);
try {
    byte[] buf = new byte[buffersize];
    int count;
    while ((count = fis.read(buf, 0, buffersize)) != -1) {
        os.write(buf, 0, count);
} finally {
    fis.close();
booleancopyFile(File fileSrc, File fileDest)
copy File
FileInputStream fileInputStream = null;
FileOutputStream fileOutputStream = null;
try {
    fileInputStream = new FileInputStream(fileSrc);
    fileOutputStream = new FileOutputStream(fileDest);
    int iBufferSize = 1024 * 1024; 
    byte byaryBuffer[] = new byte[iBufferSize];
    for (int i = 0; i < fileSrc.length() / iBufferSize; i++) 
...
voidcopyFile(File fileToCopy, File targetDir)
Copies specified file to the target directory
if (!fileToCopy.exists()) {
    throw new IllegalArgumentException();
if (!targetDir.isDirectory()) {
    throw new IllegalArgumentException();
copyDirectory(fileToCopy, new File(targetDir, fileToCopy.getName()), null);
voidcopyFile(File from, File to)
copy File
try {
    FileInputStream inputStream = new FileInputStream(from);
    FileOutputStream outputStream = new FileOutputStream(to);
    byte[] b = new byte[1024];
    int n = 0;
    while ((n = inputStream.read(b)) != -1) {
        outputStream.write(b, 0, n);
    inputStream.close();
    outputStream.flush();
    outputStream.close();
} catch (FileNotFoundException e) {
    e.printStackTrace();
} catch (IOException e) {
    e.printStackTrace();
voidcopyFile(File from, File to)
copy File
if (from.isDirectory()) {
    if (!to.exists()) {
        to.mkdir();
    String[] children = from.list();
    for (int i = 0; i < children.length; i++) {
        File f = new File(from, children[i]);
        if (f.getName().equals(".") || f.getName().equals("..")) {
...
voidcopyFile(File from, File to)
copy File
byte[] buf = new byte[1024];
FileInputStream in = new FileInputStream(from);
try {
    FileOutputStream out = new FileOutputStream(to);
    try {
        int numRead = in.read(buf);
        while (numRead != -1) {
            out.write(buf, 0, numRead);
...
voidcopyFile(File from, File to)
copy File
FileInputStream input = null;
FileOutputStream output = null;
try {
    input = new FileInputStream(from);
    output = new FileOutputStream(to);
    copyStream(input, output);
} finally {
    if (input != null) {
...
voidcopyFile(File from, File to)
copy File
if (!from.exists() || !to.exists()) {
    return;
copyAndCloseStrams(new FileInputStream(from), new FileOutputStream(to));
voidcopyFile(File from, File to)
copy File
if (from.isDirectory()) {
    copyDir(from, to);
} else {
    FileInputStream fromIn = new FileInputStream(from);
    FileOutputStream toOut = new FileOutputStream(to);
    try {
        copy(fromIn, toOut);
    } finally {
...