Here you can find the source of writeString(String s, DataOutputStream writer)
public static void writeString(String s, DataOutputStream writer) throws Exception
//package com.java2s; //License from project: Open Source License import java.io.ByteArrayOutputStream; import java.io.DataOutputStream; public class Main { public static void writeString(String s, DataOutputStream writer) throws Exception { if (s != null) { ByteArrayOutputStream bos = new ByteArrayOutputStream(); DataOutputStream dos = new DataOutputStream(bos); byte[] data = s.getBytes("UTF-8"); dos.writeInt(data.length);/* www . jav a 2 s. c om*/ dos.write(data); dos.flush(); byte[] bs = bos.toByteArray(); writer.write(bs); writer.flush(); } } }