Reputation: 16211
I am trying to write a large String into my DataOutputStream however I am getting a UTFDataFormatException
that says:
String more than 65535 UTF bytes long
This happens when I call:
byteOut.writeUTF(stringArray.get(i));
byteOut being my DataOutputStream
and stringArray.get(i);
being my string.
Is there anyway to get large string into this DataOutputStream
or is there another solution.
Thanks!
Upvotes: 2
Views: 1710
Reputation: 16211
I found the solution to my problem and here it is.
ByteArrayOutputStream baos = new ByteArrayOutputStream();
DataOutputStream byteOut = new DataOutputStream(baos);
byte[] data = stringArray.get(i).getBytes("UTF-8");
byteOut.write(data);
byteOut.close();
byte[] input = baos.toByteArray();
May not be, and probably isn't perfect but it works.
Upvotes: 2