Read from file with BufferedInputStream : BufferedInputStream « File Input Output « Java






Read from file with BufferedInputStream

  

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

   
    
  








Related examples in the same category

1.Create BufferedInputStream from FileInputStream
2.Read File in String Using Java BufferedInputStream Example
3.Read File Using Java BufferedInputStream Example
4.Use buffered streams to copy a file
5.Import a file of exported preference data.
6.Copy byte between BufferedInputStream and BufferedOutputStream
7.Fast BufferedInputStream