packagecom.tutorialspoint;importjava.io.ByteArrayOutputStream;importjava.io.IOException;publicclassByteArrayOutputStreamDemo{publicstaticvoidmain(String[]args)throwsIOException{Stringstr="";byte[]bs={65,66,67,68,69};ByteArrayOutputStreambaos=null;try{// create new ByteArrayOutputStreambaos=newByteArrayOutputStream();// write byte array to the output streambaos.write(bs);// converts buffers content using Cp1047 character setstr=baos.toString("Cp1047");System.out.println(str);// converts buffers contents using UTF-8 character setstr=baos.toString("UTF-8");System.out.println(str);}catch(Exceptione){// if I/O error occurse.printStackTrace();}finally{if(baos!=null)baos.close();}}}