public class JsonFileReader {
public static String getJson(Context context, String fileName) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try {
AssetManager assetManager = context.getAssets();
InputStream inputStream = assetManager.open(fileName);
BufferedInputStream bufferedInputStream = new BufferedInputStream(inputStream);
byte[] buffer = new byte[1024];
int len;
while ((len = bufferedInputStream.read(buffer)) != -1) {
baos.write(buffer, 0, len);
}
} catch (IOException e) {
e.printStackTrace();
}finally {
try {
baos.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return baos.toString();
}
}
上方读出来是一个字符串至于解析就要大家自己写了
fileName 中传入assets的命名就可以