import java.net.*; public class ExampleClass { public static void main(String[] args) { try { Socket s = new Socket("example.com", 80); // check if output stream is closed if (s.isOutputShutdown()) { System.out.println("Output stream is closed."); } else { System.out.println("Output stream is open."); } s.close(); // close the socket } catch (Exception e) { e.printStackTrace(); } } }
import java.net.*; public class ExampleClass { public static void main(String[] args) { try { ServerSocket ss = new ServerSocket(1234); Socket s = ss.accept(); // accept client connection // check if output stream is closed if (s.isOutputShutdown()) { System.out.println("Output stream is closed."); } else { System.out.println("Output stream is open."); } s.close(); // close the socket ss.close(); // close the server socket } catch (Exception e) { e.printStackTrace(); } } }In this example, we create a server socket on port 1234 and accept a client connection. We then use the isOutputShutdown() method to check if the output stream is closed. Again, since we haven't written anything to the stream yet, it should be open. Finally, we close both sockets. The java.net package library contains classes for networking on the Java platform, including sockets, URLs, and protocols like HTTP and FTP.