/* The ByteArrayInputStream is composed of two words: ByteArray and InputStream. As the name suggests, it can be used to read byte array as input stream. Java ByteArrayInputStream class contains an internal buffer which is used to read byte array as stream. In this stream, the data is read from a byte array. The buffer of ByteArrayInputStream automatically grows according to data. */ /* Java ByteArrayOutputStream class is used to write common data into multiple files. In this stream, the data is written into a byte array which can be written to multiple streams later. The ByteArrayOutputStream holds a copy of data and forwards it to multiple streams. The buffer of ByteArrayOutputStream automatically grows according to data. */ import java.io.*; public class ByteArrayTest { public static void main(String args[])throws Exception{ FileOutputStream fout1=new FileOutputStream("f1.txt"); FileOutputStream fout2=new FileOutputStream("f2.txt"); byte[] buf = { 35, 36, 37, 38 }; ByteArrayInputStream byt = new ByteArrayInputStream(buf); int k = 0; char ch; while ((k = byt.read()) != -1) { //Conversion of a byte into character ch = (char) k; ByteArrayOutputStream bout=new ByteArrayOutputStream(); bout.write(ch); bout.writeTo(fout1); bout.writeTo(fout2); } bout.flush(); bout.close();//has no effect System.out.println("Success..."); } }