Read File in String Using Java BufferedInputStream Example : BufferedInputStream « File Input Output « Java






Read File in String Using Java BufferedInputStream Example

  

import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;

public class Main {

  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;
    while ((bytesRead = bin.read(contents)) != -1) {
      strFileContents = new String(contents, 0, bytesRead);
      System.out.print(strFileContents);
    }
    bin.close();
  }
}

   
    
  








Related examples in the same category

1.Create BufferedInputStream from FileInputStream
2.Read from file with BufferedInputStream
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