首页 > 移动平台 > 详细

Android读程序包的资源

时间:2015-06-05 15:34:14      阅读:132      评论:0      收藏:0      [点我收藏+]
    private static final String ENCODING = "utf-8";

    public static String loadText(Context context, String assetFilePath){
        InputStream is = null;
        try {
            is = context.getResources().getAssets().open(assetFilePath);
            String textfile = convertStreamToString(is);
            return textfile;
        } catch (IOException e) {
            e.printStackTrace();
        }

        return null;
    }

    public static String convertStreamToString(InputStream is)
            throws IOException {
        Writer writer = new StringWriter();

        char[] buffer = new char[2048];
        try {
            Reader reader = new BufferedReader(new InputStreamReader(is,
                    ENCODING));
            int n;
            while ((n = reader.read(buffer)) != -1) {
                writer.write(buffer, 0, n);
            }
        } finally {
            is.close();
        }
        String text = writer.toString();
        return text;
    }
}

 

Android读程序包的资源

原文:http://www.cnblogs.com/xbx2015/p/4554654.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!