Is there a reason why java does not have a class which allows both reading String and byte [] from a stream and also another for writing String and byte [] to a stream? What if it is necessary to transfer both byte [] and String like in HTTP?
Share
There would likely be potential issues with character encodings. In particular, Java internally represents strings in UTF-16, which probably isn’t what, say, someone on the other end of a network connection is expecting. The resulting behavior would be consistent, but not necessarily what the average programmer would expect.
Getting a
byte[]representation of a String isn’t hard. Just useString.getBytes(), or the overloaded version which allows you to specify the encoding.