Example usage for java.io BufferedInputStream read

List of usage examples for java.io BufferedInputStream read

Introduction

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

Prototype

public synchronized int read() throws IOException 

Source Link

Document

See the general contract of the read method of InputStream.

Usage

From source file:BufferedInputStreamDemo.java

public static void main(String args[]) throws Exception {
    FileInputStream fis = new FileInputStream(args[0]);

    BufferedInputStream bis = new BufferedInputStream(fis);

    int i;//  ww w.java 2  s. co  m
    while ((i = bis.read()) != -1) {
        System.out.println(i);
    }

    fis.close();
}

From source file:MainClass.java

public static void main(String args[]) {
    try {/*w w w  .  j a  v a 2s  . com*/
        FileInputStream fis = new FileInputStream(args[0]);

        BufferedInputStream bis = new BufferedInputStream(fis);

        int i;
        while ((i = bis.read()) != -1) {
            System.out.println(i);
        }
        fis.close();
    } catch (Exception e) {
        System.out.println("Exception: " + e);
    }
}

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   w  w w  .  ja v  a 2  s.co  m
    buffer.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);
    while (bin.available() > 0) {
        System.out.println((char) bin.read());
    }//from w w w  . ja va2 s .  c om
    bin.close();
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    InputStream iStream = new FileInputStream("c:/test.txt");
    BufferedInputStream bis = new BufferedInputStream(iStream);

    // read and print characters one by one
    System.out.println((char) bis.read());
    System.out.println((char) bis.read());
    System.out.println((char) bis.read());

    // mark is set on the input stream
    bis.mark(0);/*from  w ww.  j a v  a 2 s. co  m*/
    System.out.println((char) bis.read());

    // reset is called
    bis.reset();

    // read and print characters
    System.out.println((char) bis.read());
    System.out.println((char) bis.read());

}

From source file:Main.java

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

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

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

    // read and print characters one by one
    System.out.println((char) bis.read());
    System.out.println((char) bis.read());
    System.out.println((char) bis.read());

    // mark is set on the input stream
    bis.mark(0);//from w ww .  j av a  2 s . co m
    System.out.println((char) bis.read());
    System.out.println("reset() invoked");

    // reset is called
    bis.reset();

    // read and print characters
    System.out.println((char) bis.read());
    System.out.println((char) bis.read());

}

From source file:BufferedInputStreamDemo.java

public static void main(String args[]) throws IOException {
    String s = "This is a © copyright symbol " + "but this is &copy not.\n";
    byte buf[] = s.getBytes();
    ByteArrayInputStream in = new ByteArrayInputStream(buf);
    BufferedInputStream f = new BufferedInputStream(in);
    int c;//from w w w .ja  va2  s . co m
    boolean marked = false;

    while ((c = f.read()) != -1) {
        switch (c) {
        case '&':
            if (!marked) {
                f.mark(32);
                marked = true;
            } else {
                marked = false;
            }
            break;
        case ';':
            if (marked) {
                marked = false;
                System.out.print("(c)");
            } else
                System.out.print((char) c);
            break;
        case ' ':
            if (marked) {
                marked = false;
                f.reset();
                System.out.print("&");
            } else
                System.out.print((char) c);
            break;
        default:
            if (!marked)
                System.out.print((char) c);
            break;
        }
    }
}

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;//  w  ww .j a va 2  s .com
    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 {

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

    BufferedInputStream bis = new BufferedInputStream(inStream);

    // read until a single byte is available
    while (bis.available() > 0) {
        // read the byte and convert the integer to character
        char c = (char) bis.read();

        System.out.println(c);/*from   w  w  w  .  j  a  v a  2 s.  com*/
    }
}

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 ww .j  a  v  a  2  s . c  o m

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

    bos.flush();

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

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

}