Example usage for java.io BufferedInputStream BufferedInputStream

List of usage examples for java.io BufferedInputStream BufferedInputStream

Introduction

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

Prototype

public BufferedInputStream(InputStream in) 

Source Link

Document

Creates a BufferedInputStream and saves its argument, the input stream in, for later use.

Usage

From source file:Main.java

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

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

    // input stream is converted to buffered input stream
    BufferedInputStream bis = new BufferedInputStream(is);

}

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;// w  w  w . jav a  2s  . c o m
    while ((len = in.read(buff)) > 0)
        out.write(buff, 0, len);
    in.close();
    out.close();
}

From source file:MainClass.java

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

    URL u = new URL("http://www.java2s.com");
    InputStream in = u.openStream();

    in = new BufferedInputStream(in);

    Reader r = new InputStreamReader(in);
    int c;//from w  ww.  j ava2  s. c  om
    while ((c = r.read()) != -1) {
        System.out.print((char) c);
    }
}

From source file:Main.java

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

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

    // input stream is converted to buffered input stream
    BufferedInputStream bis = new BufferedInputStream(is);

    // read until a single byte is available
    while (bis.available() > 0) {
        // skip single byte from the stream
        bis.skip(1);/*from  w  w w .j ava2 s. c o  m*/

        // read next available byte and convert to char
        char c = (char) bis.read();
        System.out.print(c);
    }
}

From source file:Main.java

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

    FileInputStream is = new FileInputStream("c:/test.txt");

    BufferedInputStream bis = new BufferedInputStream(is);

    ByteArrayOutputStream baos = new ByteArrayOutputStream();

    BufferedOutputStream bos = new BufferedOutputStream(baos);

    int value;/*from   w  w  w.ja v a 2 s  . co m*/

    while ((value = bis.read()) != -1) {
        bos.write(value);
    }

    bos.flush();

    for (byte b : baos.toByteArray()) {

        char c = (char) b;
        System.out.println(c);
    }

}

From source file:Main.java

public static void main(String[] args) throws Exception {
    int i = 0;//from w w w . j a  va  2 s .  co  m

    // create input streams
    InputStream is = new FileInputStream("C://test.txt");
    FilterInputStream fis = new BufferedInputStream(is);

    // read till the end of the stream
    while ((i = fis.read()) != -1) {
        // converts integer to character
        char c = (char) i;

        System.out.println("Character read: " + c);
    }

}

From source file:Main.java

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

    int i = 0;//from  w  w w .ja v a  2 s  .co m

    InputStream is = new FileInputStream("C://test.txt");
    FilterInputStream fis = new BufferedInputStream(is);

    while ((i = fis.read()) != -1) {
        char c = (char) i;

        System.out.print("Read: " + c);

        int j = fis.available();

        System.out.println("; Available bytes: " + j);
    }
}

From source file:Main.java

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

    // create input streams
    InputStream is = new FileInputStream("C://test.txt");
    FilterInputStream fis = new BufferedInputStream(is);

    // closes and releases the associated system resources
    fis.close();// ww w . j  av a  2  s.com

    // read is called after close() invocation
    fis.read();

}

From source file:Main.java

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

    byte[] buffer = new byte[6];

    InputStream is = new FileInputStream("C://test.txt");
    FilterInputStream fis = new BufferedInputStream(is);

    // returns number of bytes read to buffer
    int i = fis.read(buffer, 2, 4);

    System.out.println("Number of bytes read: " + i);

    // for each byte in buffer
    for (byte b : buffer) {
        // converts byte to character
        char c = (char) b;

        // if byte is null
        if (b == 0) {
            c = '-';
        }/*from w  w w  .  j av  a  2s.co m*/
        System.out.println("Char read from buffer b: " + c);
    }

}

From source file:Main.java

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

    int i = 0;/* ww w  .  java2s. c o  m*/

    // create input streams
    InputStream is = new FileInputStream("C://test.txt");
    FilterInputStream fis = new BufferedInputStream(is);

    while ((i = fis.read()) != -1) {
        // converts integer to character
        char c = (char) i;

        // skips 3 bytes
        fis.skip(3);

        System.out.println("Character read: " + c);
    }

}