Android 读取资源文件asstes路径

来源:互联网 发布:开心保健康保 知乎 编辑:程序博客网 时间:2024/06/06 00:15


第一种方法:

       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;

    }

第三种方法。读取。.ini文件中。某一个key=value的值:

/*    */   public static final String getDebugValue(Context context, String key)/*    */   {/* 37 */     String value = null;/*    */     try {/* 39 */       String packageName = "config";/* 40 */       Properties prop = new Properties();/* 41 */       AssetManager am = context.getAssets();/* 42 */       InputStream is = am.open(packageName + ".ini");/* 43 */       prop.load(is);/* 44 */       value = prop.getProperty(key);/*    */     }/*    */     catch (Exception e) {/* 47 */       e.printStackTrace();/*    */     }/* 49 */     return value;/*    */   }/*    */ }




http://www.cnblogs.com/sybz/archive/2011/12/17/2774565.html
0 0
原创粉丝点击