About Question enthuware.ocpjp.v8.2.1775 :
Posted: Tue Jun 21, 2016 11:36 am
In the explanation:
Since ObjectOutputStream.writeUTF is supported and a BufferedWriter does not support writeUTF?
Wouldn't you really need something like:FileWriter is a concrete subclass of java.io.Writer that writes data to the underlying file in default encoding. If you want to write text in a different encoding, you will need to create an OutputStreamWriter with that encoding. For example,You can then create a BufferedWriter over this OutputStreamWriter.Code: Select all
OutputStreamWriter osw = new OutputStreamWriter( new FileOutputStream("utf8.txt"), Charset.forName("UTF-8").newEncoder() );
Code: Select all
CharsetEncoder ce = Charset.forName("UTF-8").newEncoder();
try (
FileOutputStream fos = new FileOutputStream("utf8.txt");
OutputStreamWriter osw = new OutputStreamWriter(fos, ce);
ObjectOutputStream oos = new ObjectOutputStream(fos); ){
oos.writeUTF("hello");
}