1. 程式人生 > >Android 獲取assets的絕對路徑

Android 獲取assets的絕對路徑

第一種方法:
       String path = "file:///android_asset/檔名";

第二種方法:
    InputStream abpath = getClass().getResourceAsStream("/assets/檔名");


若要想要轉換成String型別

String path = new String(InputStreamToByte(abpath ));


    private byte[] InputStreamToByte(InputStream is) throws IOException {
        ByteArrayOutputStream bytestream = new ByteArrayOutputStream();

        int ch;
        while ((ch = is.read()) != -1) {
            bytestream.write(ch);
        }
        byte imgdata[] = bytestream.toByteArray();
        bytestream.close();
        return imgdata;

    }

http://www.cnblogs.com/sybz/archive/2011/12/17/2774565.html