List of utility methods to do FileChannel Copy
void | copyFile(File src, File dst) copy File long p = 0, dp, size; FileChannel in = null, out = null; try { if (!dst.exists()) dst.createNewFile(); in = new FileInputStream(src).getChannel(); out = new FileOutputStream(dst).getChannel(); size = in.size(); ... |
void | copyFile(File src, File dst) copies the contents of a file FileInputStream in = new FileInputStream(src); FileOutputStream out = new FileOutputStream(dst); copyChannel(in.getChannel(), src.length(), (WritableByteChannel) out.getChannel()); in.close(); out.close(); |
void | copyFile(File src, File dst) Copy a file to another folder if (src == null) { throw new IllegalArgumentException("File src can't be null!!"); if (dst == null) { throw new IllegalArgumentException("File dst can't be null!!"); if (!src.exists()) { throw new FileNotFoundException("File " + src.getName() + " can't be found!"); ... |
void | copyFile(File src, File dst) copy File FileChannel c1 = new RandomAccessFile(src, "r").getChannel(); FileChannel c2 = new RandomAccessFile(dst, "rw").getChannel(); long tCount = 0, size = c1.size(); while ((tCount += c2.transferFrom(c1, 0, size - tCount)) < size) { c1.close(); c2.force(true); c2.close(); ... |
void | copyFile(File src, File target) copy File prepareWrite(target); try (FileInputStream in = new FileInputStream(src); FileOutputStream out = new FileOutputStream(target)) { FileChannel chin = in.getChannel(); FileChannel chout = out.getChannel(); chin.transferTo(0, chin.size(), chout); |
boolean | copyFile(File src, File target) copy File boolean flag = false; FileInputStream in = null; FileOutputStream out = null; try { in = new FileInputStream(src); out = new FileOutputStream(target); FileChannel inCh = in.getChannel(); FileChannel outCh = out.getChannel(); ... |
void | copyFile(File srcFile, File destFile, boolean preserveFileDate) From Apache Commons FileUtils if (srcFile == null) { throw new NullPointerException("Source must not be null"); if (destFile == null) { throw new NullPointerException("Destination must not be null"); if (srcFile.exists() == false) { throw new FileNotFoundException("Source '" + srcFile + "' does not exist"); ... |
void | copyFile(File srcFile, File destFile, boolean preserveFileDate) Copies a file to a new location. if (srcFile == null) { throw new NullPointerException("Source must not be null"); if (destFile == null) { throw new NullPointerException("Destination must not be null"); if (srcFile.exists() == false) { throw new FileNotFoundException("Source '" + srcFile + "' does not exist"); ... |
void | copyFile(File srcFile, File destFile, boolean preserveFileDate) 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(File srcFile, File dstFile, boolean overwrite) copy File if (dstFile.isDirectory()) throw new IOException("copyFile: destination is a directory: " + dstFile.getAbsolutePath()); if (dstFile.exists() && !overwrite) throw new IOException("copyFile: destination file already exists: " + dstFile.getAbsolutePath()); FileChannel srcChannel = null; FileChannel dstChannel = null; try { srcChannel = new FileInputStream(srcFile).getChannel(); ... |