Java 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(File from, File to)
copy
try {
    File w = new File(to, from.getName());
    if (!w.exists())
        w.createNewFile();
    BufferedOutputStream write = new BufferedOutputStream(new FileOutputStream(w));
    BufferedInputStream read = new BufferedInputStream(new FileInputStream(from));
    byte[] buffer = new byte[1024];
    int l = 0;
...
voidcopyFile(File source, File target)
copy File
copyFile(source.toPath(), target.toPath());
voidcopyFile(File src, File dest, Component parentComponent, String message)
copy File
InputStream in = new FileInputStream(src);
OutputStream out = new FileOutputStream(dest);
copyFile(in, out, parentComponent, message);
out.flush();
out.close();
in.close();
dest.setLastModified(src.lastModified());
voidcopyFileFromFileSystem(String sourceFileName, File target)
copy File From File System
try {
    File in = new File(sourceFileName);
    FileChannel inChannel = new FileInputStream(in).getChannel();
    FileChannel outChannel = new FileOutputStream(target).getChannel();
    try {
        inChannel.transferTo(0, inChannel.size(), outChannel);
    } catch (IOException e) {
        throw e;
...
voidcopyFiles(File file, File destPath)
Copy files to destPath, can be a folder.
if (file.isDirectory()) {
    File dest = new File(destPath, file.getName());
    File[] files = file.listFiles();
    for (File subFile : files) {
        copyFiles(subFile, dest);
} else {
    copyFile(file, destPath);
...
voidcopyFiles(File fromDir, File toDir)
Copies all files in fromDir to toDir.
String[] names = fromDir.list();
if (names != null) {
    for (int i = 0; i < names.length; i += 1) {
        File fromFile = new File(fromDir, names[i]);
        if (fromFile.isDirectory()) {
            continue;
        File toFile = new File(toDir, names[i]);
...
voidcopyFiles(File source, File destination)
Copies the contents of one file to another.
copyStreams(new FileInputStream(source), new FileOutputStream(destination));
voidcopyFiles(File sourceFile, File targetDir)
Copies an existing structure to a new destination.
copyFiles(sourceFile, sourceFile, targetDir);
voidcopyFiles(File src, File dest)
This function will copy files or directories from one location to another.
if (!src.exists()) {
    throw new IOException("copyFiles: Can not find source: " + src.getAbsolutePath() + ".");
} else if (!src.canRead()) { 
    throw new IOException("copyFiles: No right to source: " + src.getAbsolutePath() + ".");
if (src.isDirectory()) {
    if (!dest.exists()) { 
        if (!dest.mkdirs()) {
...
voidcopyFiles(File src, File dest)
Copy files.
if (!src.exists()) {
    throw new IOException("Resource does not exist: " + src.getAbsolutePath());
} else if (!src.canRead()) {
    throw new IOException("Insufficient privileges to open: " + src.getAbsolutePath());
if (src.isDirectory()) {
    if (!dest.exists() || !dest.mkdirs()) {
        throw new IOException("Cannot create: " + dest.getAbsolutePath());
...