import java.io.*; public class ByteArrayOutputStreamDemo { public static void main(String[] args) { String s = "abcdefghijklmnopqrstuvwxyz"; ByteArrayOutputStream bas = new ByteArrayOutputStream(); bas.writeBytes(s.getBytes()); byte[] b = bas.toByteArray(); for(int c: b) System.out.print((char)c); System.out.println(); } }