EncodingUtils 过时,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; }