Here you can find the source of loadFile(URL resource)
Parameter | Description |
---|---|
resource | a parameter |
Parameter | Description |
---|---|
IOException | an exception |
public static byte[] loadFile(URL resource) throws IOException
//package com.java2s; //License from project: Open Source License import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; import java.net.URL; public class Main { /**/*from w ww . j ava 2 s.c om*/ * Load the content from the URL into a byte array. * * @param resource * @return * @throws IOException */ public static byte[] loadFile(URL resource) throws IOException { InputStream is = resource.openStream(); try { ByteArrayOutputStream bos = new ByteArrayOutputStream(); byte[] buffer = new byte[1024]; int n; while ((n = is.read(buffer)) > 0) { bos.write(buffer, 0, n); } return bos.toByteArray(); } finally { is.close(); } } }