您的位置:首页 > 其它

获得assets资源文件夹下的文本文件方法

2015-06-02 15:32 501 查看
//获得资源文件夹下的文本文件
 public String getText(String name){
   try {
   //Return an AssetManager instance for your application's package
             InputStream is = getAssets().open(name);
             int size = is.available();
   
             // Read the entire asset into a local byte buffer.
             byte[] buffer = new byte[size];
             is.read(buffer);
             is.close();
   
             text = new String(buffer, "GB2312");
   
         } catch (IOException e) {
             // Should never happen!
             throw new RuntimeException(e);
         }
  return text;
 }
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: