List of utility methods to do File Copy nio
File | copyToTmpFile(InputStream in, String prefix, String suffix) copy To Tmp File File tempFile = File.createTempFile(prefix, suffix); tempFile.deleteOnExit(); copy(in, new FileOutputStream(tempFile)); return tempFile; |
void | fileCopy(File source, File destination) Copy file source to destination . if (destination.exists()) { throw new IllegalArgumentException("Cannot overwrite existing file"); FileChannel sourceChannel = null, destChannel = null; try { sourceChannel = new FileInputStream(source).getChannel(); destChannel = new FileOutputStream(destination).getChannel(); destChannel.transferFrom(sourceChannel, 0, sourceChannel.size()); ... |
void | fileCopy(File source, File target) file Copy if (!target.getParentFile().exists()) { target.getParentFile().mkdirs(); Files.copy(new FileInputStream(source.getAbsolutePath().replace("%20", " ")), target.toPath(), StandardCopyOption.REPLACE_EXISTING); |
void | fileCopy(File sourceFile, File destFile) file Copy FileChannel source = null; FileChannel destination = null; FileInputStream fis = null; FileOutputStream fos = null; try { fis = new FileInputStream(sourceFile); fos = new FileOutputStream(destFile); source = fis.getChannel(); ... |
void | fileCopy(File src, File dest) file Copy if (!dest.exists()) { final File parent = new File(dest.getParent()); if (!parent.exists() && !parent.mkdirs()) { throw new IOException(); if (!dest.exists() && !dest.createNewFile()) { throw new IOException(); try (final FileInputStream is = new FileInputStream(src); final FileOutputStream os = new FileOutputStream(dest); final FileChannel srcChannel = is.getChannel(); final FileChannel dstChannel = os.getChannel()) { dstChannel.transferFrom(srcChannel, 0, srcChannel.size()); |
void | fileCopy(final File dest, final File src) file Copy FileInputStream in = null; FileOutputStream out = null; try { in = new FileInputStream(src); out = new FileOutputStream(dest); FileChannel fcin = in.getChannel(); FileChannel fcout = out.getChannel(); long bytes = fcin.size(); ... |