class FileUtils {

    public static byte[] resourceToBytes(String resourceName) {
        ClassLoader cl = Thread.currentThread().getContextClassLoader();
        InputStream is = cl.getResourceAsStream(resourceName);

        if (is == null)
            return null;

        try {
            is = new BufferedInputStream(is);
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            byte[] buffer = new byte[1024];
            int n;

            while ((n = is.read(buffer)) != -1) {
                baos.write(buffer, 0, n);
            }
            is.close();
            return baos.toByteArray();
        }
        catch (Exception e) {
                try {
                    is.close();
                }
                catch (Exception ex) {
                    // ignore...
                }
            return null;
        }
    }

}