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

voidcopy(String source, String destinction)
copy
File sourceFile = new File(source);
copy(sourceFile, destinction);
voidcopy(String srcFileName, String destFileName)
This may be a resource leak: http://bugs.sun.com/view_bug.do?bug_id=4724038 We may have to reconsider using nio for this, or apply one of the horrible workarounds listed in the bug report above.
if (srcFileName == null) {
    throw new IllegalArgumentException("srcFileName is null");
if (destFileName == null) {
    throw new IllegalArgumentException("destFileName is null");
FileChannel src = null;
FileChannel dest = null;
...
voidcopyBundleFile(IPath projectRelativePath, String outputPath)
copy Bundle File
InputStream is = null;
FileOutputStream to = null;
try {
    is = FileLocator.openStream(getBundle(), projectRelativePath,
            false);
    to = new FileOutputStream(outputPath);
    byte[] buffer = new byte[4096];
    int bytesRead;
...
booleancopyFile(File fin, File fout)
copy File
FileInputStream in = null;
FileOutputStream out = null;
try {
    in = new FileInputStream(fin);
    out = new FileOutputStream(fout);
    copyFile(in, out);
    in.close();
    out.close();
...
booleancopyFile(File from, File to)
Copies one file to another, overwriting the destination file.
return copyFile(from, to, false);
booleancopyFile(File from, File to, boolean append)
Copies one file to another, optionally appending.
boolean ok = true;
try {
    BufferedInputStream in = new BufferedInputStream(
            new FileInputStream(from), 64 * 1024);
    BufferedOutputStream out = new BufferedOutputStream(
            new FileOutputStream(to, append), 64 * 1024);
    byte[] buf = new byte[8 * 1024];
    int len = 0;
...
booleancopyFile(File from, File to, byte[] buf)
copy File
if (buf == null)
    buf = new byte[BUFFER_SIZE];
FileInputStream from_s = null;
FileOutputStream to_s = null;
try {
    from_s = new FileInputStream(from);
    to_s = new FileOutputStream(to);
    for (int bytesRead = from_s.read(buf); bytesRead > 0; bytesRead = from_s
...
booleancopyFile(File in, File out)
copy File
try {
    return copyFile(new FileInputStream(in), new FileOutputStream(
            out));
} catch (Exception e) {
    e.printStackTrace();
    return false;
voidcopyFile(File source, File dest)
copy File
if (!isValidFile(source))
    return;
FileInputStream in = null;
FileOutputStream out = null;
byte[] buffer = new byte[1024 * 64]; 
int bytesRead = -1;
try {
    in = new FileInputStream(source);
...
booleancopyFile(File source, File destination)
copy File
FileInputStream inputStream = null;
FileOutputStream outputStream = null;
FileChannel fcin = null;
FileChannel fcout = null;
try {
    inputStream = new FileInputStream(source);
    outputStream = new FileOutputStream(destination);
    fcin = inputStream.getChannel();
...