how to obtain length of a UTF-encoded string before writing it?

W

wnstnsmith

Dear all,

I need to know howmany bytes will be written by writeUTF("blabla") before
actually writing the string to file.
how do I do that?

all help much appreciated.

WS
 
M

Michael Borgwardt

I need to know howmany bytes will be written by writeUTF("blabla") before
actually writing the string to file.
how do I do that?

String utfString = "Struffüöäßéì漢字もã‚ã‚‹";
int byteLength = utfString.getBytes("UTF-8").length + 2;
 
O

Omar Khan

writeUTF
First, two bytes are written to the output stream as if by the
writeShort method giving the number of bytes to follow.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top