直接上代码
//key为键值
public static String getJsonStr(String key, Context context) {
Properties props = loadProperties(context);
String apiKey = props.getProperty(key, "");
try {
return new String(apiKey.getBytes("ISO-8859-1"), "utf-8");//有可能有乱码,加此代码
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
return "";
}
public static Properties loadProperties(Context context) {
Properties props = new Properties();
try {
int id = context.getResources().getIdentifier("alljsonstr", "raw",
context.getPackageName());//意思是读取raw中的alljsonstr文件
props.load(context.getResources().openRawResource(id));
} catch (Exception e) {
e.printStackTrace();
}
return props;
}