在我的项目中,我需要创建一个文本文件并从该文件中读取特定内容。我需要知道在哪个目录下放置该文件,以便我可以在我的java代码中成功地读取它?
这应该放在/assets/
目录下。
还可以阅读这篇关于Android初学者:资源和资产简介的教程。
AssetManager assetManager = getAssets();
InputStream stream = null;
try {
stream = assetManager.open("file.txt");
} catch (IOException e) {
// handle
}
finally {
if (stream != null) {
try {
stream.close();
} catch (IOException e) {}
}
}