Here you can find the source of writeString(String str, DataOutputStream dos)
public static void writeString(String str, DataOutputStream dos) throws IOException
//package com.java2s; // %InstallDIR%\features\org.talend.rcp.branding.%PRODUCTNAME%\%PRODUCTNAME%license.txt import java.io.DataOutputStream; import java.io.IOException; import java.io.ObjectOutputStream; public class Main { private static final String UTF8 = "UTF-8"; /**//w ww. j av a2 s. c o m * DOC zhao Comment method "writeString". * * @param line * @param dos * @throws IOException */ public static void writeString(String str, ObjectOutputStream dos) throws IOException { if (str == null) { dos.writeInt(-1); } else { byte[] byteArray = str.getBytes(UTF8); dos.writeInt(byteArray.length); dos.write(byteArray); } } public static void writeString(String str, DataOutputStream dos) throws IOException { if (str == null) { dos.writeInt(-1); } else { byte[] byteArray = str.getBytes(UTF8); dos.writeInt(byteArray.length); dos.write(byteArray); } } }