Here you can find the source of getBytes(String urlStr)
public static byte[] getBytes(String urlStr)
//package com.java2s; //License from project: Apache License import java.io.ByteArrayOutputStream; import java.io.InputStream; import java.net.URL; import java.net.URLConnection; public class Main { /** read url into byte[] */ public static byte[] getBytes(String urlStr) { try {/* ww w .ja va 2 s . c o m*/ URL u = new URL(urlStr); URLConnection uc = u.openConnection(); InputStream is = uc.getInputStream(); byte[] buf = new byte[4096]; ByteArrayOutputStream baos = new ByteArrayOutputStream(); while (true) { int read = is.read(buf); if (read == -1) { break; } baos.write(buf, 0, read); } is.close(); baos.close(); return baos.toByteArray(); } catch (Exception e) { e.printStackTrace(); } return null; } }