List of utility methods to do FileInputStream Copy
void | copyFileToDir(File oldFile, File outputDir) Copies a file into a specified directory FileInputStream in = new FileInputStream(oldFile); File destFile = new File(outputDir, oldFile.getName()); FileOutputStream out = new FileOutputStream(destFile); copyStream(in, out); in.close(); out.close(); destFile.setLastModified(oldFile.lastModified()); |
void | copyFileToDir(File sourceFile, File destDir) copy File To Dir FileInputStream in = new FileInputStream(sourceFile); FileOutputStream out = new FileOutputStream( destDir.getAbsolutePath() + File.separator + sourceFile.getName()); byte[] buffer = new byte[1024]; int bytesRead; while ((bytesRead = in.read(buffer)) > -1) { out.write(buffer, 0, bytesRead); out.flush(); out.close(); |
void | copyFileToDir(String targetDir, String[] filePath) Copy many files to one directory File targetFile = new File(targetDir); if (!targetFile.exists()) { targetFile.mkdirs(); } else { if (!targetFile.isDirectory()) { return; for (String path : filePath) { File file = new File(path); if (file.isDirectory()) { copyFileToDir(targetDir + File.separator + file.getName(), listFile(file)); } else { copyFileToDir(targetDir, file); |
void | CopyFileToDirectory(String file_name, String from_directory, String to_directory) Copy File To Directory InputStream inStream = null; OutputStream outStream = null; try { File afile = new File(from_directory + "/" + file_name); File bfile = new File(to_directory + "/" + file_name); inStream = new FileInputStream(afile); outStream = new FileOutputStream(bfile); byte[] buffer = new byte[1024]; ... |
void | copyFileToFile(File file, File destFile, boolean overwrite) Copy a file to another file. if ((!overwrite) && destFile.isFile()) { throw new IllegalStateException("Destination file " + destFile + " already exists"); if (destFile.isDirectory()) { throw new IllegalStateException("Destination file is an existing directory"); try (FileInputStream in = new FileInputStream(file); FileOutputStream out = new FileOutputStream(destFile)) { ... |
File | copyFileToFile(File input, String outputPath, String exportName) copy File To File File file = new File(outputPath, exportName); try { DataOutputStream out = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(file))); FileInputStream is = new FileInputStream(input); byte[] buf = new byte[1024]; int len; while ((len = is.read(buf)) > 0) { out.write(buf, 0, len); ... |
void | copyFileToOutputStream(File file, OutputStream stream) Write a file to an output stream copyInputStream(new FileInputStream(file), stream);
|
void | copyFileToOutputStream(String fileLocation, OutputStream os) copy File To Output Stream FileInputStream fis = new FileInputStream(fileLocation);
copyStream(fis, os);
|
void | copyFileToStream(File currentFile, OutputStream outputStream) copy File To Stream int read = 0; byte[] buffer = new byte[8192]; FileInputStream in = new FileInputStream(currentFile); while (-1 != (read = in.read(buffer))) { outputStream.write(buffer, 0, read); in.close(); |
void | copyFileToStream(File file, OutputStream stream) Copies the data from file into the stream. FileInputStream input = new FileInputStream(file); long longLength = file.length(); final int fiveMegabytes = 5 * 1024 * 1024; while (longLength > 0) { int chunk = (int) Math.min(longLength, fiveMegabytes); byte[] data = new byte[chunk]; input.read(data, 0, chunk); stream.write(data, 0, chunk); ... |