我想使用Assets文件夹中的文件,但是在我的应用程序中我想以Java而不是Activity类的形式获取该文件。请帮助我该怎么做。
我的意思是,我想编写一些代码来使用Java文件中的Async Task解析json文件,其中我的Json文件位于Asset文件夹中。
为此,我需要扩展什么类别,以及如何访问Assets中的文件。
谢谢
最佳答案
尝试这个:
AssetManager assetManager = getResources().getAssets();
InputStream inputStream = null;
try {
inputStream = assetManager.open("YourFile.txt");
if ( inputStream != null)
Log.d(TAG, "It worked!");
} catch (IOException e) {
e.printStackTrace();
}
不使用
InputStream是= assetManager.open(“ assets / YourFile.txt”);
希望对您有所帮助!