DataOutputStream output = new DataOutputStream(new FileOutputStream("output.txt")); int num = 10; output.writeInt(num); output.close();
DataOutputStream output = new DataOutputStream(socket.getOutputStream()); String message = "Hello, world!"; output.writeUTF(message); output.close();In this example, we create a new DataOutputStream object that writes to a socket's output stream. We then write a string value of "Hello, world!" to the socket using the writeUTF() method. Overall, java.io.DataOutputStream is a useful class for writing binary data to various output streams in a consistent and machine-independent manner.