Android 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

booleancopy(File inFile, File outFile)
This method copies one file to another location
if (!inFile.exists()) {
    return false;
FileChannel in = null;
FileChannel out = null;
try {
    in = new FileInputStream(inFile).getChannel();
    out = new FileOutputStream(outFile).getChannel();
...
voidcopy(File pSourceFile, File pTargetFile)
copy
if (!pSourceFile.getCanonicalPath().equals(
        pTargetFile.getCanonicalPath())) {
    pTargetFile.getParentFile().mkdirs();
    FileInputStream lFIS = new FileInputStream(pSourceFile);
    FileOutputStream lFOS = new FileOutputStream(
            pTargetFile.getCanonicalPath());
    copy(lFIS, lFOS);
    lFOS.close();
...
voidcopy(File source, File target, boolean append)
Copies source to target.
Check.arg().validFile(source);
Check.arg().notNull(target);
if (source.getCanonicalPath().equals(target.getCanonicalPath()))
    throw new IllegalArgumentException(
            "source and target resolve to the same path = "
                    + source.getCanonicalPath());
InputStream in = null;
OutputStream out = null;
...
voidcopy(File sourceFile, File destinationFile)
copy
FileReader reader = null;
FileWriter writer = null;
try {
    reader = new FileReader(sourceFile);
    writer = new FileWriter(destinationFile);
    int data = reader.read();
    while (data != -1) {
        writer.write(data);
...
voidcopy(File sourceFile, File targetFile)
Copy the source file to the target file.
copy(sourceFile, targetFile, false);
booleancopy(File sourceFile, File targetFile, boolean overwrite)
Copy the source file to the target file while optionally permitting an overwrite to occur in case the target file already exists.
boolean overwriteOccurred = false;
if (targetFile.exists()) {
    if (!overwrite) {
        throw new FileAlreadyExistsException("Target file "
                + targetFile + " already exists");
    } else {
        overwriteOccurred = true;
FileInputStream fis = new FileInputStream(sourceFile);
FileOutputStream fos = new FileOutputStream(targetFile);
fis.getChannel().transferTo(0, sourceFile.length(),
        fos.getChannel());
fis.close();
fos.flush();
fos.close();
return overwriteOccurred;
voidcopy(File sourceFile, String destinction)
copy
if (!sourceFile.exists())
    return;
File dest_f = new File(destinction);
if (!dest_f.exists())
    dest_f.mkdirs();
if (sourceFile.isDirectory()) {
    java.io.File[] files = sourceFile.listFiles();
    for (int i = 0; files != null && i < files.length; i++) {
...
voidcopy(File src, File dest)
copy
if (src.isDirectory()) {
    if (!dest.exists()) {
        dest.mkdir();
    String files[] = src.list();
    for (String file : files) {
        File srcFile = new File(src, file);
        File destFile = new File(dest, file);
...
booleancopy(String input, String output)
This class copies an input file to output file
int BUFSIZE = 65536;
FileInputStream fis = new FileInputStream(input);
FileOutputStream fos = new FileOutputStream(output);
try {
    int s;
    byte[] buf = new byte[BUFSIZE];
    while ((s = fis.read(buf)) > -1) {
        fos.write(buf, 0, s);
...
voidcopy(String pSourceFile, String pTargetFile)
copy
copy(new File(pSourceFile), new File(pTargetFile));