List of utility methods to do File Copy
void | copyFile(String origPath, String destPath) Convenience function to copy a file. FileChannel in = null; FileChannel out = null; try { in = new FileInputStream(origPath).getChannel(); out = new FileOutputStream(destPath).getChannel(); in.transferTo(0, in.size(), out); } finally { if (in != null) ... |
void | copyFile(String sourceFileName, String destinationFileName) copy File copyFile(new File(sourceFileName), new File(destinationFileName)); |
void | copyFile(String sourcePath, String destPath) Copies one file to another. File sourceFile = new File(sourcePath); File destFile = new File(destPath); if (!destFile.exists()) { destFile.createNewFile(); FileChannel source = null; FileChannel destination = null; try { ... |
void | copyFile(String sourcePathName, String destPathName) copy File copyFile(new File(sourcePathName), new File(destPathName)); |
Boolean | copyFile(String srcFile, String destFile) copies a file to a new location on the local file system. Boolean copyFlag = false; File inputFile = new File(srcFile); File outputFile = new File(destFile); try { FileReader in = new FileReader(inputFile); FileWriter out = new FileWriter(outputFile); int c; while ((c = in.read()) != -1) ... |
boolean | copyFile(String strSrc, String strDest) Copy file from src to des, override if des exist FileInputStream isSrc = null; FileOutputStream osDest = null; try { File flDest = new File(strDest); if (flDest.exists()) flDest.delete(); File flSrc = new File(strSrc); if (!flSrc.exists()) ... |
void | copyFileByCommand(String src, String dst, boolean isMove) Use system command to copy file File file = new File(dst).getParentFile(); if (!file.exists() && !file.mkdirs()) return; String[] cmd = null; if (System.getProperty("os.name").toLowerCase() .startsWith("windows")) { cmd = new String[5]; cmd[0] = "cmd"; ... |
void | copyFileLazy(String source, String destination) copy File Lazy String oldContent = null; try { oldContent = FileUtil.read(source); } catch (FileNotFoundException fnfe) { return; String newContent = null; try { ... |
void | copyFileToFile(File file, File outFile) Copy a file to a location given by another file. FileInputStream in = new FileInputStream(file); FileOutputStream out = new FileOutputStream(outFile); byte[] buf = new byte[512]; int l; try { while ((l = in.read(buf)) > 0) { out.write(buf, 0, l); out.flush(); } catch (IOException e) { throw e; } finally { try { out.close(); } catch (Exception ignored) { try { in.close(); } catch (Exception ignored) { |
void | copyFiles(File src, File dst) copy files from src to dst if (!src.exists()) return; else if (src.isDirectory() && !dst.isFile()) { if (dst.exists() || dst.mkdirs()) { File[] subSrcs = src.listFiles(); for (File subSrc : subSrcs) { File subDst = new File(dst.getPath() + File.separator + subSrc.getName()); ... |