Here you can find the source of copyFileRecursivlyLinewise(File inDir, File outDir)
Parameter | Description |
---|---|
inDir | directory that shall be copied |
outDir | directory the files and directories shall be copied to |
Parameter | Description |
---|---|
IOException | thrown if reading or writing has failed |
public static void copyFileRecursivlyLinewise(File inDir, File outDir) throws IOException
//package com.java2s; //License from project: Open Source License import java.io.*; public class Main { /**//from ww w . j a va 2 s .c o m * Copies the directory structure with all the included files to a new directory. * The files are processed linewise, i.e., the OS specific newline character will be used * to break lines. * * @param inDir directory that shall be copied * @param outDir directory the files and directories shall be copied to * @throws IOException thrown if reading or writing has failed */ public static void copyFileRecursivlyLinewise(File inDir, File outDir) throws IOException { File[] inputFiles = inDir.listFiles(); for (File inputFile : inputFiles) { File outputFile = new File(outDir, inputFile.getName()); // copy program files line-wise to convert use OS specific newlines if (inputFile.isFile()) { copyFileLinewise(inputFile, outputFile); } else { File newOutDir = new File(outDir, inputFile.getName()); newOutDir.mkdir(); copyFileRecursivlyLinewise(inputFile, newOutDir); } } } /** * Copies one file linewise to another file. * * @param inputFile input file (that shall be copied) * @param outputFile destination file * @throws IOException thrown if reading or writing has failed */ public static void copyFileLinewise(File inputFile, File outputFile) throws IOException { 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(); } } }