List of utility methods to do FileChannel Copy
void | copyFile(FileChannel in, FileChannel out) Optimized copy from one file to another long position = 0; long read; while ((read = in.transferTo(position, 16 * 1024, out)) > 0) { position += read; |
void | copyFile(FileInputStream fromFile, FileOutputStream toFile) Creates the specified toFile as a byte for byte copy of the fromFile .
FileChannel fromChannel = null; FileChannel toChannel = null; try { fromChannel = fromFile.getChannel(); toChannel = toFile.getChannel(); fromChannel.transferTo(0, fromChannel.size(), toChannel); } finally { try { ... |
void | copyFile(final File in, final File out) Copy the input file to output file FileChannel inChannel = new FileInputStream(in).getChannel(); FileChannel outChannel = new FileOutputStream(out).getChannel(); try { inChannel.transferTo(0, inChannel.size(), outChannel); } catch (IOException e) { throw e; } finally { if (inChannel != null) { ... |
void | copyFile(final File in, final File out) copy File RandomAccessFile f1 = new RandomAccessFile(in, "r"); RandomAccessFile f2 = new RandomAccessFile(out, "w"); try { FileChannel c1 = f1.getChannel(); FileChannel c2 = f2.getChannel(); try { c1.transferTo(0, f1.length(), c2); c1.close(); ... |
void | copyFile(final File input, final File output) This method can be used to copy a file from one place to another. FileInputStream in = null; FileOutputStream out = null; try { in = new FileInputStream(input); out = new FileOutputStream(output); FileChannel inChannel = in.getChannel(); FileChannel outChannel = out.getChannel(); long size = inChannel.size(); ... |
void | copyFile(final File src, final File dest) Copies a File source file to a File destination file . if (!readable(src)) { throw new IOException(format("%s: unreadable", src)); if (!writable(dest)) { throw new IOException(format("%s: unwritable", src)); FileInputStream srcInput = null; FileChannel srcChannel = null; ... |
void | copyFile(final File src, final File dst) Copies the source file to the destination file if (!src.exists()) { throw new FileNotFoundException("File does not exist: " + src.getAbsolutePath()); if (!dst.exists()) { dst.createNewFile(); FileChannel source = null; FileChannel destination = null; ... |
boolean | copyFile(final File srcFile, final File destFile) Copy a file. return copyFile(srcFile, destFile, false);
|
void | copyFile(final File srcFile, final File destFile) copy File if (destFile.exists() && destFile.isDirectory()) { throw new IOException("Destination '" + destFile + "' exists but is a directory"); FileInputStream fis = null; FileOutputStream fos = null; FileChannel input = null; FileChannel output = null; try { ... |
void | copyFile(final String src, final String dest) copy File copyFile(new File(src), new File(dest)); |