集册 Java实例教程 将字符串写入DataOutputStream

将字符串写入DataOutputStream

欢马劈雪     最近更新时间:2020-01-02 10:19:05

783
将字符串写入DataOutputStream


//package com.nowjava;


import java.io.DataOutputStream;/** 来自 时   代    Java - nowjava.com**/

import java.io.IOException;


public class Main {

    public static void writeString(DataOutputStream out, String string)

            throws IOException {

        out.writeInt(string.length());

        out.writeChars(string);

    }


    public static void writeInt(DataOutputStream out, int i)

            throws IOException {

        out.writeInt(i);

    }

}