Java URL Load loadURL(URL url)

Here you can find the source of loadURL(URL url)

Description

Load URL contents int a byte array

License

Open Source License

Declaration

public static byte[] loadURL(URL url) throws Exception 

Method Source Code


//package com.java2s;
import java.io.ByteArrayOutputStream;

import java.io.InputStream;
import java.net.URL;

public class Main {
    /**//  w w  w.j av  a 2s. co m
     * Load URL contents int a byte array
     */
    public static byte[] loadURL(URL url) throws Exception {
        byte[] buf = new byte[1024];
        InputStream is = null;
        ByteArrayOutputStream bout = new ByteArrayOutputStream();
        try {
            is = url.openStream();
            int n;
            while (-1 != (n = is.read(buf))) {
                bout.write(buf, 0, n);
            }
            return bout.toByteArray();
        } finally {
            try {
                is.close();
            } catch (Exception e) {
            }
        }
    }
}

Related

  1. loadProps(URL url, Properties props)
  2. loadRemoteJSON(final URL source)
  3. loadText(URL url, boolean allowCache)
  4. loadURL(String urlDesc)
  5. loadURL(URL url)
  6. loadUrlIntoByteArray(String urlString)
  7. loadUrlToList(URL iUrl)
  8. loadURLToString(String url, String EOL)
  9. read(String url)