public static void writeString(String s, DataOutputStream out) throws IOException
    {
        out.writeInt(s.length());
        for (char c : s.toCharArray())
        {
            out.writeChar(c);
        }
    }
public static void writeString ( String s , DataOutputStream out ) throws IOException { out . writeInt ( s . length ( ) ) ; for ( char c : s . toCharArray ( ) ) { out . writeChar ( c ) ; } }
简单好用的写String方式

@param s
@param out
@throws IOException