socket.getOutputStream(); java
时间: 2023-12-27 12:44:34 浏览: 25
The `getOutputStream()` method in Java returns an output stream for writing bytes to the socket. It is used to send data from the client to the server or vice versa through the socket connection. The returned output stream can be used to write bytes of data to the socket.
Here is an example of how `getOutputStream()` can be used in Java:
```
Socket socket = new Socket("localhost", 8080);
OutputStream outputStream = socket.getOutputStream();
outputStream.write("Hello, server!".getBytes());
```
In this example, we first create a new socket object that connects to the server running on localhost at port 8080. Then, we get the output stream for the socket using `getOutputStream()` and write the string "Hello, server!" to the output stream using the `write()` method. This sends the data to the server through the socket connection.