在java中怎样将一个字符串写如一个流中
展开全部
可以使用DataoutputStream
比如
DataoutputStream dos = new DataOutputStream(client.getOutputStream()); //client是Socket对象
dos.writeUTF(str); //str为字符串对象
或者
Socket server = new Socket(InetAddress.getLocalHost(), 5678);
PrintWriter out = new PrintWriter(server.getOutputStream());
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
out.println(reader.readLine());
比如
DataoutputStream dos = new DataOutputStream(client.getOutputStream()); //client是Socket对象
dos.writeUTF(str); //str为字符串对象
或者
Socket server = new Socket(InetAddress.getLocalHost(), 5678);
PrintWriter out = new PrintWriter(server.getOutputStream());
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
out.println(reader.readLine());
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询