Java PrintWriter File Overwrite -
i want write file using utf-16 use printwriter(file,"utf-16"), deletes in file, use filewriter(file,true), wouldn't in utf-16, , there apparently isn't constructor printwriter printwriter(writer,charset,boolean append);
what should do?
the javadoc filewriter
says:
the constructors of class assume default character encoding , default byte-buffer size acceptable. specify these values yourself, construct
outputstreamwriter
onfileoutputstream
.
so can do:
writer writer = new printwriter( new outputstreamwriter( new fileoutputstream(filename, true), standardcharsets.utf16));
you might want include bufferedoutputstream
in there maximum efficiency.
Comments
Post a Comment