arrayList<File> to folder containing those files java -


i have arraylist<file>.

and need write files output_directory computer

this 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);             out.close();         }         catch (exception e){             system.out.println(e.tostring());         }     } 

the corpus arraylist of files

the error

java.io.filenotfoundexception: diroutput/name of file  

(no files or directories of types)

most output directory doesn't exist. create output directory first , error gone. also, can use files.copy() java.nio.file avoid create multiple filewriter instances

try {     files.copy(         paths.get(file.getabsolutepath()),         paths.get(new file("<correct path>", file.getname()).getabsolutepath())); } catch (ioexception e) {     e.printstacktrace(); }  

Comments

Popular posts from this blog

java - SSE Emitter : Manage timeouts and complete() -

jquery - uncaught exception: DataTables Editor - remote hosting of code not allowed -

java - How to resolve error - package com.squareup.okhttp3 doesn't exist? -