在安卓开发中,如何获取assets文件夹下面的文件配置
public static String getAssetsContent(String fileName, Context ctx) {
StringBuilder stringBuffer = new StringBuilder();
AssetManager assetManager = ctx.getAssets();
try {
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(assetManager.open(fileName), "utf-8"));
String line;
while ((line = bufferedReader.readLine()) != null) {
stringBuffer.append(line);
}
} catch (IOException e) {
e.printStackTrace();
}
return stringBuffer.toString();
}
使用方法直接调用getAssetsContent方法
String config = getAssetsContent("文件名",content);
评论(0)