EncodingUtils 过时

xiaoxiao2021-02-28  97

EncodingUtils:deprecated  过时,API level 21之后可用,

new String(byte[] data, String charsetName)这个构造函数,可以运行在任意API Level

public static String readFileFromAssets(Context context,String fileName) { String res=""; try{ InputStream in = context.getResources().getAssets().open(fileName); int length = in.available(); byte [] buffer = new byte[length]; in.read(buffer); in.close(); //res = EncodingUtils.getString(buffer, "UTF-8");//EncodingUtils:deprecated 过时,API level 21之后是不可以的 res = new String(buffer, "UTF-8");//用new String可以运行在任意API Level }catch(Exception e){ e.printStackTrace(); } return res; }

转自:http://blog.csdn.net/u010477502/article/details/52525417

转载请注明原文地址: https://www.6miu.com/read-32465.html

最新回复(0)