Read File in String Using Java BufferedInputStream Example : BufferedInputStream « File « Java Tutorial






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








11.9.BufferedInputStream
11.9.1.BufferedInputStream
11.9.2.Buffered Stream Copier
11.9.3.Read from file with BufferedInputStream
11.9.4.Read File in String Using Java BufferedInputStream Example
11.9.5.Read File Using Java BufferedInputStream Example
11.9.6.Use buffered streams to copy a file
11.9.7.Import a file of exported preference data.
11.9.8.Save keyboard input with BufferedInputStream