I am working on a spring boot application and needed to use toByteArray method provided by IOUtils, but it is deprecated. Is it safe to use string.getBytes() instead in a spring boot application or is there another way to get bytes from a text content?
Best is to use,
string.getBytes("UTF-8");
It is better to specify the encoding else default platform specific encoding may be used which may create unexpected results in case you have characters that can't be represented in default encoding like Arabic/Chinese/Hindi characters.
And UTF-8 is one of the best and compact encodings and covers over a million characters in other languages and emojis as well.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With