posted 13 years ago
I don't understand the point of that code. To me it seems like a waste of typing, but maybe there's something there which I don't understand.
You have a method called "packString" which writes String data in UTF-8 format to an array of bytes and then converts those bytes back to a String using some unknown encoding (your system's default charset, whatever that is). Converting binary bytes to a String is rarely a good idea, as String is not meant to be a container for arbitrary bytes. In the best case your system's default charset would be UTF-8, in which case packString would just give you back your original String. In other cases you get a mangled version of your original String.
And then you have "unpackString" which takes a String, converts it to bytes using that same unknown encoding, and then tries to read those bytes assuming they were encoded in UTF-8. But since you get that error message, that means they weren't encoded in UTF-8.
You can make the error message go away by specifying the UTF-8 encoding in your toString() and getBytes() method, but since that results in packString() returning the original String, there doesn't seem to be any point in that. But as I said, there's a good chance I don't understand what that code is supposed to be for.
I also notice that you aren't closing your output stream properly (the variable "dos"). So perhaps you're losing the last part of the data as well.