List of utility methods to do BufferedReader Copy
void | copyFile(String srcFile, String dstFile) Copy a file. try { FileInputStream fis = new FileInputStream(new File(srcFile)); FileOutputStream fos = new FileOutputStream(new File(dstFile)); try { byte[] buf = new byte[40960]; int i = 0; while ((i = fis.read(buf)) != -1) { fos.write(buf, 0, i); ... |
void | copyFile(String srcFileName, String destFileName) Copy a file to another position BufferedReader br = new BufferedReader(new FileReader(srcFileName)); BufferedWriter bw = new BufferedWriter(new FileWriter(destFileName)); String line; while ((line = br.readLine()) != null) { bw.write(line); bw.newLine(); br.close(); ... |
boolean | copyFile2(String source, String out) copy File try { FileReader fr = new FileReader(new File(source)); BufferedReader bfr = new BufferedReader(fr); FileWriter frout = new FileWriter(new File(out)); BufferedWriter bfrout = new BufferedWriter(frout); char[] ss = new char[1024]; int nbr = 0; while (bfr.ready() && ((nbr = bfr.read(ss, 0, ss.length)) != -1)) { ... |
void | copyFileContentsIntoAnotherFile(String inputFileName, PrintWriter Out) copy File Contents Into Another File BufferedReader br = new BufferedReader(new FileReader(inputFileName)); try { String line = br.readLine(); while (line != null) { Out.println(line); line = br.readLine(); } finally { ... |
void | copyFileFromJar(File jarFile, File targetFile, String sourceFilePath) copy File From Jar InputStream is = null; FileOutputStream fos = null; BufferedReader reader = null; BufferedWriter writer = null; File parent = targetFile.getParentFile(); if (!parent.exists()) { parent.mkdirs(); try { JarFile jar = new JarFile(jarFile); ZipEntry zipEntry = jar.getEntry(sourceFilePath); is = jar.getInputStream(zipEntry); fos = new FileOutputStream(targetFile); reader = new BufferedReader(new InputStreamReader(is, "UTF-8")); writer = new BufferedWriter(new OutputStreamWriter(fos)); String line; while ((line = reader.readLine()) != null) { writer.write(line); writer.newLine(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally { if (writer != null) { try { writer.flush(); writer.close(); } catch (IOException e) { if (reader != null) { try { reader.close(); } catch (IOException e) { if (fos != null) { try { fos.flush(); fos.close(); } catch (IOException e) { if (is != null) { try { is.close(); } catch (IOException e) { |
void | copyFileLinewise(File inputFile, File outputFile) Copies one file linewise to another file. try { BufferedReader r = new BufferedReader(new FileReader(inputFile)); BufferedWriter w = new BufferedWriter(new FileWriter(outputFile)); String line; while ((line = r.readLine()) != null) { w.write(line); w.newLine(); w.close(); r.close(); } catch (FileNotFoundException e) { e.printStackTrace(); |
void | copyFileRecursivlyLinewise(File inDir, File outDir) Copies the directory structure with all the included files to a new directory. File[] inputFiles = inDir.listFiles(); for (File inputFile : inputFiles) { File outputFile = new File(outDir, inputFile.getName()); if (inputFile.isFile()) { copyFileLinewise(inputFile, outputFile); } else { File newOutDir = new File(outDir, inputFile.getName()); newOutDir.mkdir(); ... |
void | copyFileTextMode(String source, String destination) copy File Text Mode String readLine = null; BufferedReader readSource = new BufferedReader(new FileReader(new File(source))); BufferedWriter writeSource = new BufferedWriter(new FileWriter(new File(destination), true)); while ((readLine = readSource.readLine()) != null) { writeSource.write(readLine); writeSource.newLine(); writeSource.close(); ... |
void | copyFileWithAppend(File source, File destination) copy File With Append if (!destination.exists()) { destination.getParentFile().mkdirs(); destination.createNewFile(); if (!source.exists()) { throw new IOException("Source file must exist!"); BufferedReader sourceReader = new BufferedReader(new FileReader(source)); ... |