Java DataOutputStream Write String writeString(DataOutputStream out, String str)

Here you can find the source of writeString(DataOutputStream out, String str)

Description

Writes a string to a DataInputStream.

License

Open Source License

Parameter

Parameter Description
out DataOutputStream to write to.
str The string to write.

Exception

Parameter Description
IOException if an I/O error occurs.

Declaration

public static void writeString(DataOutputStream out, String str) throws IOException 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.io.DataOutputStream;
import java.io.IOException;

public class Main {
    /**//from   ww w .  j a  v  a2 s.  c o  m
     * Writes a string to a DataInputStream.
     * @param out DataOutputStream to write to.
     * @param str The string to write.
     * @throws IOException if an I/O error occurs.
     */
    public static void writeString(DataOutputStream out, String str) throws IOException {
        out.writeShort(str.length());

        for (char letter : str.toCharArray()) {
            out.writeChar(letter);
        }
    }
}

Related

  1. writeString(DataOutputStream os, String s)
  2. writeString(DataOutputStream os, String str)
  3. writeString(DataOutputStream out, String s)
  4. writeString(DataOutputStream out, String str)
  5. writeString(DataOutputStream out, String str)
  6. writeString(DataOutputStream out, String text)
  7. writeString(DataOutputStream out, String theString)
  8. writeString(DataOutputStream out, String val)
  9. writeString(DataOutputStream output, String s)