....怀疑了一下咋会不行呢,花点时间敲个例子,说明 context 直接 getAssets 就可以,难道还有版本问题??
assets 里有个 hello.txt ,里面有行文字:hello asset
代码:
public class MyApp extends Application {
@
Override public void onCreate() {
super.onCreate();
test();
}
private void test() {
Log.e("flag--", "run(MyApp.java)---->>" + Thread.currentThread().getName());
try {
InputStream open = getAssets().open("hello.txt");
InputStreamReader reader = new InputStreamReader(open);
BufferedReader bufferedReader = new BufferedReader(reader);
Log.e("flag--", "run(MyApp.java)---->>" + bufferedReader.readLine());
} catch (IOException aE) {
aE.printStackTrace();
}
}
}
logcat:
2019-05-17 09:19:54.497 30636-30636/com.haibin.calendarviewproject E/flag--: run(MyApp.java)---->>main
2019-05-17 09:19:54.498 30636-30636/com.haibin.calendarviewproject E/flag--: run(MyApp.java)---->>hello asset