public class InputStreamExample1 { static final int SIZE = 1024 * 1024 * 256; static final byte[] BYTES = new byte[SIZE]; // we don't care what's inside public static void main(String[] args) throws IOException { ByteArrayOutputStream os = new ByteArrayOutputStream(); os.write(BYTES); os.close(); InputStream is = new ByteArrayInputStream(os.toByteArray()); byte[] bytes = new byte[SIZE]; int bytesRead = is.read(bytes); System.out.println("Read " + bytesRead + " bytes."); } }