-
Notifications
You must be signed in to change notification settings - Fork 8
How to read file in Java – BufferedInputStream
Ramesh Fadatare edited this page Jul 17, 2018
·
3 revisions
-
Overview In this example, we will use BufferedInputStream class to read file. The BufferedInputStream class is used to read information from stream. It internally uses buffer mechanism to make the performance fast.
-
Example
package com.javaguides.javaio.fileoperations.examples;
import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.IOException;
public class BufferedInputStreamExample {
public static void main(String[] args) {
try( FileInputStream fin=new FileInputStream("D:\\testout.txt");
BufferedInputStream bin=new BufferedInputStream(fin); ){
int i;
while((i=bin.read())!=-1){
System.out.print((char)i);
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
https://docs.oracle.com/javase/8/docs/api/java/io/BufferedInputStream.html https://docs.oracle.com/javase/tutorial/essential/exceptions/tryResourceClose.html