Popular Posts
Build an OpenVPN server on android device Preparation An android device, in this case, Sony xperia Z is used Root permission required Linux Deploy for deploy i... executeOrDelayUntilScriptLoaded Executes the specified function if the file containing it is loaded; otherwise, adds it to the pending job queue. ExecuteOrDelayUntilScrip... Multiple line of text limit With Sharepoint Designer, edit the page of list view. Add xsl template as below to override original template. Source template could be foun...
Stats
ResourceReader
package bruce.lib;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;

/**
 * @author NaNashi
 * 
 */
public class ResourceReader {

    public static String readText(String path, String encoding) throws IOException {
        InputStream is = ResourceReader.class.getClassLoader().getResourceAsStream(path);
        StreamReader reader = new StreamReader(is, encoding);
        String content = reader.readToEnd();
        is.close();
        return content;
    }

    public static byte[] readBytes(String path) throws IOException {
        InputStream is = ResourceReader.class.getClassLoader().getResourceAsStream(path);
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        int value = -1;
        while ((value = is.read()) > -1)
            baos.write(value);
        baos.close();
        is.close();
        return baos.toByteArray();
    }
}