Here you can find the source of writeString(String str, ObjectOutputStream dos)
Parameter | Description |
---|---|
line | a parameter |
dos | a parameter |
Parameter | Description |
---|---|
IOException | an exception |
public static void writeString(String str, ObjectOutputStream 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"; /**/*from www . ja v a2s . co 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); } } }