BufferedInputStream and BufferedOutputStream in Java - BunksAllowed

BunksAllowed is an effort to facilitate Self Learning process through the provision of quality tutorials.

Community

BufferedInputStream and BufferedOutputStream in Java

Share This

Java I/O: BufferedInputStream

Source code
package com.t4b.test; import java.io.BufferedInputStream; import java.io.FileInputStream; public class BufferedInputStreamTest { public static void main(String[] args) { try { FileInputStream fin = new FileInputStream("test.txt"); BufferedInputStream bin = new BufferedInputStream(fin); int i; while ((i = bin.read()) != -1) { System.out.print((char) i); } bin.close(); fin.close(); } catch (Exception e) { System.out.println(e); } } }

Java I/O: BufferedOutputStream


Source code
package com.t4b.test; import java.io.BufferedOutputStream; import java.io.FileOutputStream; public class BufferedOutputStreamTest { public static void main(String[] args) { try { FileOutputStream fout = new FileOutputStream("test.txt"); BufferedOutputStream bout = new BufferedOutputStream(fout); String s = "Hello World!"; byte b[] = s.getBytes(); bout.write(b); bout.flush(); bout.close(); fout.close(); } catch (Exception e) { e.printStackTrace(); } } }

Happy Exploring!

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.