Java Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | import java.io.BufferedInputStream; import java.io.FileInputStream; public class JavaBufferedInputStream { public static void main(String[] args) { try { FileInputStream fis = new FileInputStream("file.txt"); BufferedInputStream stream = new BufferedInputStream(fis); while (stream.available() > 0) { System.out.print((char) stream.read()); } stream.close(); fis.close(); } catch (Exception ex) { System.out.println(ex.getMessage()); } } } |
Java BufferedOutputStream class uses an internal buffer to store data. It adds more efficiency than to write data directly into a stream.