Example usage for java.io BufferedInputStream close

List of usage examples for java.io BufferedInputStream close

Introduction

In this page you can find the example usage for java.io BufferedInputStream 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[] args) throws Exception {

    InputStream inStream = new FileInputStream("c:/test.txt");
    BufferedInputStream bis = new BufferedInputStream(inStream);

    int byteNum = bis.available();

    System.out.println(byteNum);// w  w w  . ja v  a 2 s. c  o m

    bis.close();

    byteNum = bis.available();
    System.out.println(byteNum);

}

From source file:Main.java

public static void main(String[] args) throws Exception {
    File file = new File("C:/ReadFile.txt");
    FileInputStream fin = new FileInputStream(file);

    BufferedInputStream bin = new BufferedInputStream(fin);
    while (bin.available() > 0) {
        System.out.println((char) bin.read());
    }/*w  w  w  . j  a v a 2  s  . co  m*/
    bin.close();
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    URLConnection urlc = new URL("http://www.google.com").openConnection();

    BufferedInputStream buffer = new BufferedInputStream(urlc.getInputStream());

    int byteRead;
    while ((byteRead = buffer.read()) != -1) {
        System.out.println((char) byteRead);
    }/*from  ww  w  .j a  va  2 s .  co m*/
    buffer.close();
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    BufferedInputStream is = new BufferedInputStream(new FileInputStream("a.exe"));
    byte[] bytes = new byte[1024];
    int len = 0;/*from w ww .ja v a2 s  .  c o  m*/

    while ((len = is.read(bytes)) >= 0) {
        new CRC32().update(bytes, 0, len);
    }
    is.close();
    System.out.println(Arrays.toString(bytes));

}

From source file:Main.java

public static void main(String[] args) throws Exception {
    byte[] buffer = new byte[1024];
    BufferedInputStream bufferedInput = new BufferedInputStream(new FileInputStream("filename.txt"));

    int bytesRead = 0;
    while ((bytesRead = bufferedInput.read(buffer)) != -1) {
        String chunk = new String(buffer, 0, bytesRead);
        System.out.print(chunk);//from w  w w  .  j a v a 2 s  .  c  o m
    }
    bufferedInput.close();
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    BufferedInputStream fin = new BufferedInputStream(new FileInputStream("in.dat"));
    BufferedOutputStream fout = new BufferedOutputStream(new FileOutputStream("out.dat"));
    int i;//from w w w.  java 2s  .  c o  m
    do {
        i = fin.read();
        if (i != -1)
            fout.write(i);
    } while (i != -1);
    fin.close();
    fout.close();
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    String fromFileName = "from.txt";
    String toFileName = "to.txt";
    BufferedInputStream in = new BufferedInputStream(new FileInputStream(fromFileName));
    BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(toFileName));
    byte[] buff = new byte[32 * 1024];
    int len;//from   www  .jav a 2 s .  co  m
    while ((len = in.read(buff)) > 0)
        out.write(buff, 0, len);
    in.close();
    out.close();
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    File file = new File("C:/ReadFile.txt");
    FileInputStream fin = new FileInputStream(file);
    BufferedInputStream bin = new BufferedInputStream(fin);

    byte[] contents = new byte[1024];
    int bytesRead = 0;
    String strFileContents;// w  ww  . j a  v  a 2 s  . c  o  m
    while ((bytesRead = bin.read(contents)) != -1) {
        strFileContents = new String(contents, 0, bytesRead);
        System.out.print(strFileContents);
    }
    bin.close();
}

From source file:PrimeReader.java

public static void main(String[] arguments) {
    try {// w  w  w. j  a v  a 2  s.c  o m
        FileInputStream file = new FileInputStream("400primes.dat");
        BufferedInputStream buff = new BufferedInputStream(file);
        DataInputStream data = new DataInputStream(buff);

        try {
            while (true) {
                int in = data.readInt();
                System.out.print(in + " ");
            }
        } catch (EOFException eof) {
            buff.close();
        }
    } catch (IOException e) {
        System.out.println("Error - " + e.toString());
    }
}

From source file:MyTest.DownloadFileTest.java

public static void main(String args[]) {
    CloseableHttpClient httpclient = HttpClients.createDefault();
    String url = "http://www.myexperiment.org/workflows/16/download/Pathways_and_Gene_annotations_for_QTL_region-v7.t2flow?version=7";
    System.out.println(url.charAt(50));
    HttpGet httpget = new HttpGet(url);
    HttpEntity entity = null;//from   w  ww .  j a  v a  2  s  . co m
    try {
        HttpResponse response = httpclient.execute(httpget);
        entity = response.getEntity();
        if (entity != null) {
            InputStream is = entity.getContent();
            String filename = "testdata/Pathways_and_Gene_annotations_for_QTL_region-v7.t2flow";
            BufferedInputStream bis = new BufferedInputStream(is);
            BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(new File(filename)));
            int readedByte;
            while ((readedByte = bis.read()) != -1) {
                bos.write(readedByte);
            }
            bis.close();
            bos.close();
        }
        httpclient.close();
    } catch (IOException ex) {
        Logger.getLogger(DownloadFileTest.class.getName()).log(Level.SEVERE, null, ex);
    }

}