Java Utililty Methods BufferedInputStream Copy

List of utility methods to do BufferedInputStream Copy

Description

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

Method

voidcopyFile(String fileName, File sourceRoot, File targetRoot, Set copied)
copy File
File sourceFile = new File(sourceRoot, fileName);
InputStream source = new BufferedInputStream(new FileInputStream(sourceFile));
File targetFile = new File(targetRoot, fileName);
targetFile.getParentFile().mkdirs();
targetFile.createNewFile();
OutputStream target = new BufferedOutputStream(new FileOutputStream(targetFile));
int count;
byte[] data = new byte[1204];
...
voidcopyFile(String from, String to)
copy File
File inCannon = new File(from);
File outCannon = new File(to);
if (inCannon.equals(outCannon)) {
    return;
outCannon.getParentFile().mkdirs();
BufferedInputStream fis = new BufferedInputStream(new FileInputStream(inCannon));
BufferedOutputStream fos = new BufferedOutputStream(new FileOutputStream(outCannon));
...
voidcopyFile(String fromFile, String toFile)
Copy a file.
File from = new File(fromFile);
File to = new File(toFile);
to.createNewFile();
FileInputStream fileInputStream = new FileInputStream(from);
BufferedInputStream in = new BufferedInputStream(fileInputStream);
FileOutputStream fileOutputStream = new FileOutputStream(to);
BufferedOutputStream out = new BufferedOutputStream(fileOutputStream);
byte[] buffer = new byte[1024];
...
voidcopyFile(String source, String dest)
Copy file 'source' to file 'dest'.
File srcFile = new File(source);
File destFile = new File(dest);
copyFile(srcFile, destFile);
voidcopyFile(String source, String destination)
copy File
BufferedInputStream inputStream = new BufferedInputStream(new FileInputStream(source));
BufferedOutputStream outputStream = new BufferedOutputStream(new FileOutputStream(destination));
int bytes;
byte[] buffer = new byte[BUFFER_SIZE];
while ((bytes = inputStream.read(buffer)) != -1) {
    outputStream.write(buffer, 0, bytes);
outputStream.flush();
...
FilecopyFile(String source, String destination)
Copy resources from a source to a destination.
return copyFile(new File(source), new File(destination));
booleancopyFile(String sourceFilePath, String destinationFilePath)
copy File
if (sourceFilePath == null || destinationFilePath == null) {
    return false;
BufferedInputStream inputStream = null;
BufferedOutputStream outputStream = null;
try {
    File inputFile = new File(sourceFilePath);
    if (!inputFile.isFile()) {
...
booleancopyFile(String src, String dest)
copy File
return copyFile(new File(src), new File(dest));
booleancopyFileBytes(String srcFileName, String tarFileName)
copy File Bytes
BufferedInputStream inBuff = null;
BufferedOutputStream outBuff = null;
try {
    inBuff = new BufferedInputStream(new FileInputStream(srcFileName));
    outBuff = new BufferedOutputStream(new FileOutputStream(tarFileName));
    byte[] b = new byte[1024 * 5];
    int len;
    while ((len = inBuff.read(b)) != -1) {
...
voidcopyFileFromStream(InputStream in, File dest)
copy File From Stream
try {
    if (!dest.exists()) {
        dest.getParentFile().mkdirs();
        dest.createNewFile();
} catch (IOException e) {
    throw e;
OutputStream out = null;
BufferedInputStream bin = new BufferedInputStream(in);
byte[] buffer = new byte[4096];
int bytesRead = 0;
try {
    out = new FileOutputStream(dest);
} catch (FileNotFoundException e1) {
    throw new RuntimeException("Impossible! File not found?!", e1);
try {
    while ((bytesRead = bin.read(buffer)) > 0) {
        out.write(buffer, 0, bytesRead);
} catch (IOException e) {
    throw e;
} finally {
    try {
        bin.close();
    } catch (IOException e) {
        throw new RuntimeException("Cannot close input stream!", e);
    try {
        out.close();
    } catch (IOException e) {
        throw new RuntimeException("Cannot close output stream!", e);