List of utility methods to do FileChannel Copy
void | copyFileOrDirectory(File source, File destination, boolean flag) copy File Or Directory if ((destination.isFile()) && (!(source.isFile()))) { throw new IOException("Impossible to copy directory"); if ((source.isFile()) && (destination.isDirectory())) { copy(source, new File(destination.getPath(), source.getName())); } else if (source.isFile()) { try { copy(source, destination); ... |
void | copyFiles(File originalFile, File destinationFile) copy Files FileInputStream fis = new FileInputStream(originalFile); FileOutputStream fos = new FileOutputStream(destinationFile); FileChannel inCh = fis.getChannel(); FileChannel outCh = fos.getChannel(); outCh.transferFrom(inCh, 0, inCh.size()); fis.close(); fos.close(); inCh.close(); ... |
void | copyFiles(File source, File dest) copy Files FileInputStream fis = null; FileOutputStream fos = null; try { fis = new FileInputStream(source); fos = new FileOutputStream(dest); FileChannel fichannel = fis.getChannel(); FileChannel foChannel = fos.getChannel(); long size = fichannel.size(); ... |
void | copyFiles(File srcFile, File dstFile, boolean overwrite) copy a file, allowing to overwrite if the destination already exists if (!srcFile.exists()) throw new IOException("Source file does not exist"); if (!overwrite && dstFile.exists()) throw new IOException("Destination file already exists"); FileChannel srcChannel = null, dstChannel = null; try { srcChannel = new FileInputStream(srcFile).getChannel(); dstChannel = new FileOutputStream(dstFile).getChannel(); ... |
void | copyFiles(final File fromFile, final File toFile) Copies the contents of the input file to the output file FileInputStream inFile = new FileInputStream(fromFile); FileOutputStream outFile = new FileOutputStream(toFile); FileChannel inChannel = inFile.getChannel(); FileChannel outChannel = outFile.getChannel(); int bytesWritten = 0; long byteCount = inChannel.size(); while (bytesWritten < byteCount) { bytesWritten += inChannel.transferTo(bytesWritten, byteCount - bytesWritten, outChannel); ... |
void | copyFileToDir(File file, File destDir) Copies file from it's location to destination dir. String name = file.getName();
String filename = destDir.getAbsolutePath() + File.separator + name;
File destFile = new File(filename);
destFile.createNewFile();
copyFileToFile(file, destFile);
|
void | copyFileToDirectory(String fileFrom, String destinationDirectory) Obtains the file name from the fileIn parameter Copies the file to the destination directory using the same file name File inFile = new File(fileFrom); String fileName = inFile.getName(); copyFile(fileFrom, destinationDirectory + "/" + fileName); |
boolean | copyFileToFolder(final String resultFile, final String targetPath) Copies stored memory leak analysis file to given folder. FileChannel inputChannel = null; FileChannel ouputChannel = null; FileInputStream inStream = null; FileOutputStream outStream = null; boolean returnValue = true; try { inStream = new FileInputStream(resultFile); inputChannel = inStream.getChannel(); ... |
void | copyFileToStream(File in, OutputStream out) copy File To Stream FileInputStream is = new FileInputStream(in); FileChannel inChannel = is.getChannel(); WritableByteChannel outChannel = Channels.newChannel(out); try { inChannel.transferTo(0, inChannel.size(), outChannel); } finally { if (is != null) is.close(); ... |
void | copyFileUsingChannel(File source, File dest) copy File Using Channel FileChannel sourceChannel = null; FileChannel destChannel = null; try { sourceChannel = new FileInputStream(source).getChannel(); destChannel = new FileInputStream(dest).getChannel(); sourceChannel.transferTo(0, sourceChannel.size(), destChannel); } finally { sourceChannel.close(); ... |