Amal Kostali Targhi Amal Kostali Targhi - 1 year ago 115
Java Question

arrayList<File> to folder containing those files java

I have an


And I need to write those files into a output_Directory into my computer

this is my code

for (File file : corpus)

try {
FileWriter fw = new FileWriter (new File(outDirName, file.getName()));
BufferedWriter bw = new BufferedWriter (fw);
PrintWriter out = new PrintWriter (bw);
catch (Exception e){

the corpus is the arraylist of files

the error is Diroutput/name of my file

(no files or directories of this types)

Answer Source

Most likely your output directory doesn't exist. So create the output directory first and the error is gone. Also, you can use Files.copy() from java.nio.file which will avoid to create multiple FileWriter instances

try {
        Paths.get(new File("<correct Path>", file.getName()).getAbsolutePath()));
} catch (IOException e) {
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download