Java 怎么将字符串写入OutputStream

2019年7月30日22:59:09Java 怎么将字符串写入OutputStream已关闭评论 1,175 660字阅读2分12秒

1.简介

Java 怎么将字符串写入OutputStream?——请看下文。

2.示例代码

/**
 * 版权所有 编程十万个怎么办(www.tah1986.com)
 */

import java.io.BufferedWriter;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.net.SocketAddress;
import java.util.Scanner;
import org.apache.log4j.Logger;

public class Main{
    
    public static final void writeString(OutputStream os, String request,
            String charsetName) throws IOException {
        OutputStreamWriter writer = new OutputStreamWriter(os, charsetName);
        BufferedWriter bw = new BufferedWriter(writer);
        bw.write(request);
        bw.write("\r\n");
        bw.flush();
    }
}

 
编程十万个怎么办