List of utility methods to do FileChannel Copy
boolean | copyFile(final String src, final String dst) Copies source file content into destination file. try { final File dstDir = new File(new File(dst).getParent()); if (ensureDirectoryExists(dstDir)) { final FileChannel srcFC = new FileInputStream(src).getChannel(); final FileChannel dstFC = new FileOutputStream(dst).getChannel(); return copyFile(srcFC, dstFC); } else { return false; ... |
void | copyFile(InputStream is, OutputStream os) copy File byte[] buf = new byte[BUF_SIZE]; int len; while ((len = is.read(buf)) > 0) { os.write(buf, 0, len); is.close(); os.close(); |
void | copyFile(java.io.File fromFile, java.io.File toFile) Copy one file to another. FileChannel toChannel; try (FileChannel fromChannel = new FileInputStream(fromFile).getChannel()) { toChannel = new FileOutputStream(toFile).getChannel(); toChannel.transferFrom(fromChannel, 0L, fromChannel.size()); toChannel.close(); |
void | copyFile(java.io.File in, java.io.File out) copy File createParentDirectoriesIfNecessary(out); java.nio.channels.FileChannel inChannel = new java.io.FileInputStream(in).getChannel(); java.nio.channels.FileChannel outChannel = new java.io.FileOutputStream(out).getChannel(); inChannel.transferTo(0, inChannel.size(), outChannel); inChannel.close(); outChannel.close(); |
void | copyFile(Path source, Path target) Copy a file and try to guarantee the copy is on disk. try (FileChannel in = FileChannel.open(source, READ)) { long size = in.size(); try (FileChannel out = FileChannel.open(target, WRITE, CREATE_NEW)) { long position = 0; while (position < size) { position += in.transferTo(position, size - position, out); out.force(false); ... |
boolean | copyFile(String fromFileName, String toFileName) copy File return copyFile(new File(fromFileName), new File(toFileName)); |
boolean | copyFile(String fromPath, String toPath) Copy the file. FileChannel fromChannel = null; FileChannel toChannel = null; try { fromChannel = new FileInputStream(fromPath).getChannel(); toChannel = new FileOutputStream(toPath).getChannel(); fromChannel.transferTo(0, fromChannel.size(), toChannel); } catch (IOException e) { return false; ... |
boolean | copyFile(String in, String out) copy File File inFile = new File(in); File outFile = new File(out); FileChannel inChannel = null; FileChannel outChannel = null; try { inChannel = new FileInputStream(inFile).getChannel(); outChannel = new FileOutputStream(outFile).getChannel(); int maxCount = (64 * 1024 * 1024) - (32 * 1024); ... |
void | copyFile(String infile, String outfile) copy File try { FileInputStream fin = new FileInputStream(infile); FileOutputStream fout = new FileOutputStream(outfile); FileChannel fcin = fin.getChannel(); FileChannel fcout = fout.getChannel(); try { fcout.transferFrom(fcin, 0, fcin.size()); } finally { ... |
void | copyFile(String inFile, String outFile) copy File File in = new File(inFile); File out = new File(outFile); FileChannel inChannel = null; FileChannel outChannel = null; try { inChannel = new FileInputStream(in).getChannel(); outChannel = new FileOutputStream(out).getChannel(); inChannel.transferTo(0, inChannel.size(), outChannel); ... |