EncodingUtilsは古い

813 ワード

EncodingUtils:deprecated  古くなると、APIレベル21の後に利用可能になり、
新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