Here you can find the source of writeString(final DataOutputStream out, final String str)
Parameter | Description |
---|---|
out | The buffer. |
str | The string. |
Parameter | Description |
---|---|
IOException | Loading the file failed. |
public static void writeString(final DataOutputStream out, final String str) throws IOException
//package com.java2s; //License from project: Open Source License import java.io.*; public class Main { private static final int MAXLEN = 65535; /**/*from ww w .ja v a2 s . c om*/ * Writes a string to the buffer. * * @param out The buffer. * @param str The string. * @throws IOException Loading the file failed. */ public static void writeString(final DataOutputStream out, final String str) throws IOException { int len = str.length(); if (len > MAXLEN) { throw new IllegalArgumentException("String too long."); } out.writeShort(len); for (int i = 0; i < len; ++i) { out.writeChar(str.charAt(i)); } } }