public static byte[] readFile(String filename) throws IOException {
        int index = filename.length() - 1;
        while(index >= 0 && filename.charAt(index) != '/') {
            index--;
        }
        String dir = filename.substring(0, index);
        
        /* create dir if necessary */
        File fileDir = new File(dir);
        if(!fileDir.exists()) {
            System.out.println("create dir: " + dir);
            fileDir.mkdirs();
        }
        
        File file = new File(filename);
        if (!file.exists()) {
            System.err.println("[Error**] File " + filename + " does not exist!");
            return null;
        }

        FileInputStream fis = null;
        byte[] content = new byte[(int)file.length()];
        try {
            fis = new FileInputStream(file);
            fis.read(content);
        }
        catch (FileNotFoundException e) {
            throw new IOException(e.toString());
        }
        catch (IOException e) {
            throw new IOException(e.toString());
        }
        finally {
            try {
                fis.close();
            } catch (IOException e) {
                throw new IOException(e.toString());
            }
        }
        return content;
    }