Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在考虑在打包应用程序时将.txt文件放入res/drawable或放入res/layoutapk 中,然后在安装后打开并从中读取以执行某些任务。这可以做到吗?如果是,请告诉我如何访问该文件,因为我不知道它的路径。
.txt
res/drawable
res/layout
.txt 文件既不是可绘制的也不是布局。你应该把它放在 res/raw 中。您可以像这样访问它:
Resources resources = this.getResources(); InputStream is = resources.openRawResource(R.raw.yourtextfile);
上面代码中省略了尝试/捕获和错误处理。