List of utility methods to do FileInputStream Copy
long | copyFile(File source, File target) copy File long total = 0; FileInputStream fis = null; OutputStream fos = null; try { fis = new FileInputStream(source); mkdirs(target.getParentFile()); fos = new BufferedOutputStream(new FileOutputStream(target)); for (byte[] buffer = new byte[1024 * 32];;) { ... |
boolean | copyFile(File source, File target) Creates a copy of a file boolean backup = true; try { byte[] buf = new byte[COPY_BUFFER_SIZE]; FileInputStream fis = new FileInputStream(source); OutputStream fos = createOutputStream(target); int len; do { len = fis.read(buf); ... |
void | copyFile(File source, File target, boolean createParents, FileFilter filter) Copies if (target.isDirectory()) { String path = target.getPath(); String name = source.getName(); target = new File(path.endsWith(File.separator) ? path + name : path + File.separator + name); File parent = target.getParentFile(); if (parent != null && !parent.exists()) { if (createParents) ... |
void | copyFile(File source, File target, boolean deleteSourceAfter) Copies a source file in a target file. if (source.isDirectory()) { if (!target.exists() && !target.mkdir()) throw new IOException("Could not create the directory " + target.getAbsolutePath()); else if (target.exists() && !target.isDirectory()) throw new IOException(target + " already exists and is not a directory."); File[] children = source.listFiles(); for (File sourceChild : children) { File destChild = new File(target, sourceChild.getName()); ... |
void | copyFile(File source, File target, boolean replaceIfExists) copy File if (!target.createNewFile()) { if (target.exists() && !replaceIfExists) { throw new IOException(String.format("File '%s' already exists. ", target.getAbsolutePath())); FileInputStream in = null; FileOutputStream out = null; byte[] b = new byte[8192]; ... |
void | copyFile(File sourceDir, File destDir, String filename) Copy a file from one directory to another. copyFile(sourceDir, destDir, filename, filename); |
void | copyFile(File sourceFile, File destDir) Copy source file to dest dir. boolean copy = false; File destFile = new File(destDir, sourceFile.getName()); if (!destFile.exists()) { copy = true; } else if (sourceFile.lastModified() > destFile.lastModified()) { copy = true; if (copy) { ... |
void | copyFile(File sourceFile, File destFile) Copies a file. FileOutputStream fos; try (FileInputStream fis = new FileInputStream(sourceFile)) { fos = new FileOutputStream(destFile); fis.getChannel().transferTo(0, sourceFile.length(), fos.getChannel()); fos.close(); |
void | copyFile(File sourceFile, File destFile) Copies the source file into the destination file. assert sourceFile.exists() && sourceFile.isFile(); destFile.getParentFile().mkdirs(); if (!destFile.getParentFile().exists()) { throw new IOException("Could not make parent directories"); destFile.createNewFile(); if (!destFile.exists()) { throw new IOException("Could not create destination file"); ... |
void | copyFile(File sourceFile, File destFile) copy File copyFile(sourceFile, destFile, false); |