In this example, you will see the use of BufferedInputStream class in java.
Read file using bufferedInputStream in java.
In this example, you will see how to read a file using a BufferedInputStream in java. BufferedInputStream is a class, that reads characters from a stream and stores it in an internal buffer. It reads the byte from file input stream. The input stream is a file "TestFile.txt". The read() method reads the bytes from the input stream.
Code:ReadFileByBufferedInputStream.java
package devmanuals.com;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
public class ReadFileByBufferedInputStream {
public static void main(String[] args) throws IOException {
File file = new File("TestFile.txt");
FileInputStream fileInStream = new FileInputStream(file);
BufferedInputStream bufferInStream = new BufferedInputStream(
fileInStream);
while (bufferInStream.available() > 0) {
System.out.print((char) bufferInStream.read());
}
}
}
Output:
| Read file using bufferedinputstream in java. |

[ 0 ] Comments