PrintWriter - Disable Default UTF8 Encoding

From the Processing Reference:
Starting with Processing release 0134, all files loaded and saved by the Processing API use UTF-8 encoding.

I am reading the contents of an EPROM using an Arduino Uno and sending the data to Processing via Serial. I am then attempting to write the individual Byte values received from the Arduino to a file on my computer using Processing. Everything is working fine except that the PrintWriter object in Processing defaults to UTF-8, which takes some of the single Byte values and saves them to the file as two-Byte values.

For example: The Byte 86 (hexadecimal) is stored in the file as two Bytes C2 86 (hexadecimal)

If I was going to read the file back to write to a new EPROM, the data would not be correct. Can anyone recommend a way to just write the raw single Byte values to a file without UTF8 encoding?

1 Like

I don’t know what your code looks like, but if you are trying to save bytes, why use PrintWriter? Why not just use saveBytes?

1 Like

Another option might be to just use the Java PrintWriter and initialize it with an OutputStream, e.g. ByteArrayOutputStream. Untested – I was just glancing over the API.

I think saveBytes should work for what I am trying to do, didn’t even realize that as an option. Thank you very much! I will respond back when I get a chance to try it out.