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

voidcopyFile(File source, File destination)
copy File
Files.copy(source, destination);
voidcopyFile(File source, File destination)
copy File
if (!source.exists()) {
    return;
if ((destination.getParentFile() != null)
        && (!destination.getParentFile().exists())) {
    destination.getParentFile().mkdirs();
try {
...
voidcopyFile(File source, File target)
Copies source file to target file.
Process p = Runtime.getRuntime().exec(
        new String[] { COPY_COMMAND, source.getAbsolutePath(),
                target.getAbsolutePath() });
try {
    int ret = p.waitFor();
    if (ret != 0)
        throw new IOException("Failed to copy "
                + source.getAbsolutePath() + " to "
...
voidcopyFile(File sourceFile, File destFile)
copy File
if (!destFile.exists()) {
    destFile.createNewFile();
FileChannel source = null;
FileChannel destination = null;
try {
    source = new FileInputStream(sourceFile).getChannel();
    destination = new FileOutputStream(destFile).getChannel();
...
voidcopyFile(File src, File dest)
Copies a file to a new location preserving the file date.
if (src == null)
    throw new NullPointerException("Source must not be null");
if (dest == null)
    throw new NullPointerException("Destination must not be null");
if (!src.exists())
    throw new FileNotFoundException("Source '" + src
            + "' does not exist");
if (!src.isFile())
...
voidcopyFile(File src, File dst)
Copies one file to a specified file.
File parent = dst.getParentFile();
if (!parent.exists()) {
    parent.mkdirs();
FileInputStream fis = null;
FileOutputStream fos = null;
try {
    int len = 0;
...
voidcopyFile(Path source, Path target)
Copy a file and try to guarantee the copy is on disk.
try (FileChannel in = FileChannel.open(source, READ)) {
    long size = in.size();
    try (FileChannel out = FileChannel.open(target, WRITE,
            CREATE_NEW)) {
        long position = 0;
        while (position < size) {
            position += in.transferTo(position, size - position,
                    out);
...
voidcopyFile(String from, String target)
copy File
InputStream is = ConfFileLoader.getInputStreamForFullPath(from);
copyFile(is, target);
booleancopyFile(String from, String to)
Copies one file to another
return copyFile(new File(from), new File(to));
voidcopyFile(String oldPath, String newPath)
copy File
try {
    int byteread = 0;
    File oldfile = new File(oldPath);
    if (oldfile.exists()) {
        InputStream inStream = new FileInputStream(oldPath);
        FileOutputStream fs = new FileOutputStream(newPath);
        byte[] buffer = new byte[10000];
        while ((byteread = inStream.read(buffer)) != -1) {
...