Read from file with Buffered InputStream in Java

Description

The following code shows how to read from file with Buffered InputStream.

Example


/*  w w  w . j  av  a2  s.com*/
import java.io.BufferedInputStream;
import java.io.FileInputStream;

public class Main {
  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);
    }
    bufferedInput.close();
  }
}




















Home »
  Java Tutorial »
    I/O »




Binary File
Byte Array
CharSet
Checksum
Console
Create Copy Move Delete
Directory
Drive
Encode Decode
File Attribute
File Lock
File System
GZIP
Jar File
NIO Buffer
Path
Scanner
StreamTokenizer
Temporary File
Text File
Zip