List of usage examples for java.io OutputStream close
public void close() throws IOException
From source file:Main.java
public static void main(String[] argv) throws Exception { // Create a read/writeable file channel File file = new File("filename"); FileChannel channel = new RandomAccessFile(file, "rw").getChannel(); OutputStream os = Channels.newOutputStream(channel); os.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { JarFile f = new JarFile("a.jar"); Pack200.Packer packer = Pack200.newPacker(); OutputStream out = new FileOutputStream("a.pack"); packer.pack(f, out);//from w w w. j a va 2s . c om out.close(); }
From source file:Main.java
public static void main(String[] argv) throws Exception { String command = "cat"; Process child = Runtime.getRuntime().exec(command); OutputStream out = child.getOutputStream(); out.write("some text".getBytes()); out.close(); }
From source file:Main.java
public static void main(String[] argv) throws Exception { String command = "cat"; Process child = Runtime.getRuntime().exec(command); OutputStream out = child.getOutputStream(); out.write("some text".getBytes()); out.close(); }
From source file:Main.java
public static void main(String[] argv) throws Exception { JarFile jarfile = new JarFile("filename.jar"); Manifest manifest = jarfile.getManifest(); OutputStream fos = new FileOutputStream("manifest"); jarfile.getManifest().write(fos);/*from ww w . ja va 2s .c o m*/ fos.close(); }
From source file:Main.java
public static void main(String[] args) throws IOException { URL url = new URL("http://www.java2s.com/style/download.png"); InputStream inputStream = url.openStream(); ByteArrayOutputStream output = new ByteArrayOutputStream(); byte[] buffer = new byte[1024]; int n = 0;/*from w w w . j a v a2s . com*/ while (-1 != (n = inputStream.read(buffer))) { output.write(buffer, 0, n); } inputStream.close(); byte[] data = output.toByteArray(); OutputStream out = new FileOutputStream("data.png"); out.write(data); out.close(); for (byte b : data) { System.out.printf("0x%x ", b); } }
From source file:Main.java
public static void main(String[] args) throws IOException { HttpServer server = HttpServer.create(new InetSocketAddress(8888), 0); server.createContext("/foo", new HttpHandler() { public void handle(HttpExchange t) throws IOException { t.sendResponseHeaders(200, 0); OutputStream out = t.getResponseBody(); out.write("hello world".getBytes()); out.close(); }/*from w w w. j av a2s .c o m*/ }); server.start(); }
From source file:Main.java
public static void main(String[] argv) throws Exception { int port = 443; String hostname = "hostname"; SocketFactory socketFactory = SSLSocketFactory.getDefault(); Socket socket = socketFactory.createSocket(hostname, port); InputStream in = socket.getInputStream(); OutputStream out = socket.getOutputStream(); // Read from in and write to out... in.close();// w ww . ja v a 2s. co m out.close(); }
From source file:Main.java
public static void main(String[] argv) throws Exception { int port = 443; ServerSocketFactory ssocketFactory = SSLServerSocketFactory.getDefault(); ServerSocket ssocket = ssocketFactory.createServerSocket(port); Socket socket = ssocket.accept(); InputStream in = socket.getInputStream(); OutputStream out = socket.getOutputStream(); // Read from in and write to out... in.close();//w w w .j a v a2 s. c o m out.close(); }
From source file:Main.java
public static void main(String[] args) { try {//from w ww .j a v a 2 s .c om // create a new process Process p = Runtime.getRuntime().exec("notepad.exe"); // get the output stream OutputStream out = p.getOutputStream(); // close the output stream System.out.println("Closing the output stream..."); out.close(); } catch (Exception ex) { ex.printStackTrace(); } }