android - 从Android Studio读取txt、mp3等文件

标签 android eclipse android-studio

最近我在使用 Eclipse 之前安装了 Android Studio。在使用 Eclipse 时,我可以将所有文件放在 Assets 目录中,并使用 getassets 方法访问它。例如:

InputStream ims = getAssets().open("textnew.txt");

能否请您指教:

  1. 在 Android Studio 中的什么地方存储文件?我应该自己在/res 目录中创建文件夹并将文件放在那里吗?例如:res/raw/textnew.txt
  2. 如何访问这些文件?例如,我需要打开 txt 文件以便将其内容放置到 TextView 中。怎么做?

谢谢!

最佳答案

您仍然可以在 Android Studio 中使用 asset 文件夹。

在您的应用程序目录中手动创建文件夹 asset

Using the menus : File / New / Folder / Assets Folder

我认为与 Eclispe 的唯一区别是在 Android Studio 中默认不创建该文件夹。

关于android - 从Android Studio读取txt、mp3等文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36572832/

相关文章:

java - 当堆栈跟踪仅显示 Eclipse 中的 native 方法时,如何找到导致错误的代码行

eclipse - wso2ei-6.0.0无法在eclipse中启动

android - 无法在 Android Studio 中创建项目

Android Studio 错误 "Android Gradle plugin requires Java 11 to run. You are currently using Java 1.8"

java - 为什么无论我将组件存储在何处,我的 Java 代码都无法在 Eclipse 中运行?

java - 我如何使用界面共享数据黑白 fragment 。我希望单击“编辑 fragment 1”中的文本数据的按钮显示在 fragment 2的 TextView 中

Android 库项目说 nullpointerexception

Android - Coordinator Layout、Drawer Layout 和 Fragments

android - 将Android应用发布到Google Play商店时遇到麻烦。 “Fully Shadowed APK”

android - 如何使用 AndEngine 确定在屏幕上画线的位置