java - write to file - which way is cleaner? -
i using java.io.printwriter
write text text file. wondering if better build in variable need write , give once
printwriter out = new printwriter(outputfile); out.printf("%s", myvariablewithalltext);
or if can call n
times printwriter
write block of text in for
loop.
it works in either way , there no more code, wondering better.
in cases it's better write in stream. main reason variable might take memory, stream automatically flush it's content. writing text variable manual buffering. , better way use appropriate buffering stream/writer. in case can use java.io.bufferedwriter
. so
bufferedwriter out = new bufferedwriter(new printwriter("file.txt"));
or, if prefer printwriter interface, can this
printwriter out = new printwriter(new bufferedwriter(new filewriter("file.txt")));
Comments
Post a Comment