Example usage for java.io InputStream close

List of usage examples for java.io InputStream close

Introduction

In this page you can find the example usage for java.io InputStream close.

Prototype

public void close() throws IOException 

Source Link

Document

Closes this input stream and releases any system resources associated with the stream.

Usage

From source file:Main.java

public static void main(String[] argv) throws Exception {
    File file = new File("filename");

    URI uri = file.toURI();/*from www.  j  av a 2s  . c  o  m*/
    file = new File(uri.toURL().getFile());
    InputStream is = uri.toURL().openStream();
    is.close();
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    File file = new File("filename");

    URI uri = file.toURI();/*from   ww  w  .  j a va  2 s.  c  o m*/
    System.out.println(uri);
    file = new File(uri.toURL().getFile());
    InputStream is = uri.toURL().openStream();
    is.close();
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    File file = new File("image.gif");
    System.out.println(getFormatName(file));

    InputStream is = new FileInputStream(file);
    is.close();
    System.out.println(getFormatName(is));
}

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();

    InputStream is = Channels.newInputStream(channel);

    // Close the channel
    is.close();
}

From source file:MainClass.java

public static void main(String[] args) {

    try {/*from  www .j  a v a 2s .com*/
        URL u = new URL("http://www.java2s.com");
        OutputStream out = new FileOutputStream("test.htm");
        InputStream in = u.openStream();
        DTD html = DTD.getDTD("html");
        System.out.println(html.getName());
        in.close();
        out.flush();
        out.close();
    } catch (Exception e) {
        System.err.println("Usage: java PageSaver url local_file");
    }

}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    String command = "ls";
    Process child = Runtime.getRuntime().exec(command);

    InputStream in = child.getInputStream();
    int c;/*  w w w  .ja  v a2s  .c o m*/
    while ((c = in.read()) != -1) {
        System.out.println((char) c);
    }
    in.close();
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    String command = "ls";
    Process child = Runtime.getRuntime().exec(command);

    InputStream in = child.getInputStream();
    int c;//from  ww  w .  j  a v  a  2 s  .  c o m
    while ((c = in.read()) != -1) {
        System.out.println(((char) c));
    }
    in.close();
}

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();
    out.close();/* w  w w .j  a  v a 2 s  .  c o  m*/
}

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();
    out.close();//  w w  w .ja  v a 2 s.  c  o  m
}

From source file:Main.java

public static void main(String[] args) throws Exception {

    // new input stream created
    InputStream is = new FileInputStream("C://test.txt");

    // returns true if the mark()/reset() supported.
    boolean bool = is.markSupported();
    is.close();
    System.out.print(bool);/*from www  .ja v a  2  s .  c o m*/

}