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 on fileoutputstream.

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

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -