I am reading XML files from a directory (containing thousands of files), processing the content and writing one output file for each input file. Is there a way of 're-pointing' an existing BufferedWriter
instead of creating a new instance for each file?
...
Scanner scanner;
BufferedWriter writer;
File outfile;
for (File f: directory.ListFiles[]){
scanner = new Scanner(f);
outfile = ...;
// processing input
writer = new BufferedWriter(new FileWriter(new File(outfile)));
// write the content
writer.flush();
writer.close();
}
...
It seems a waste to have to create thousands of iterations of the Scanner
and BufferedWriter
.