访问apk的资源

ran*_*vee 1 android android-resources

我正在考虑在应用程序打包时将.txt文件放入res/drawable或放入res/layoutapk中,然后在安装后打开并从中读取以执行某些任务.可以这样做吗?如果是,请告诉我如何访问该文件,因为我不知道它的路径.

Mau*_*ijk 5

.txt文件既不是可绘制文件也不是布局.你应该把它放在res/raw中.您可以访问它,如:

    Resources resources = this.getResources(); 
    InputStream is = resources.openRawResource(R.raw.yourtextfile);
Run Code Online (Sandbox Code Playgroud)

在上面的代码中省略了try/catch和errorhandling.