I’m interested in writing arrays of bytes to disk using BufferedWriter.write(). But that method wants an array of characters. I’ll have to convert the byte[] to char[]. Easy right? Well my first try in Clojure failed to convert the bytes to chars. Thus I started wondering why the BufferedWriter.write() method is so picky about wanting char[].
Note: OuputStream has a write method which takes byte[]. So my question is about the framework design choice for wanting char[] in BufferedWrite.write().
I’m interested in writing arrays of bytes to disk using BufferedWriter.write() . But that
Share
BufferedWriteris a kind ofWriter, andWriteris meant for writing characters. To output raw bytes, you want to use some type ofOutputStream— in this case, aBufferedOutputStream.(The bridge between
OutputStreamandWriteris theOutputStreamWriterclass. It’s aWriterthat takes characters, encodes them into bytes using a scheme such as UTF-8, and feeds the resulting bytes to anOutputStream.)