在装载Android的工作室一个简单的文本文件 [英] Load a simple text file in Android Studio

查看:96
本文介绍了在装载Android的工作室一个简单的文本文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

得到了使用谷歌的Andr​​oid新Studio IDE的一个全新的项目。

我试图使用 InputStreamReader的来加载一个简单的文本文件。我收到一个文件未找到例外。目前还没有任何资产/文件夹。我试图创建一个,并在许多不同的地点加入我的文件(在项目的根,在.java文件的根目录下,等...),我试着将文件来回移动,但仍然得到的文件不找到。

现在,从来没有使用Eclipse的一个问题,因为通过任何模板创建的资产文件夹。

有谁知道应该在哪里资产去还是怎么装呢?

下面是使用code,它没有在。开():

 的InputStream是= resources.getAssets()开(bla.txt)。
的BufferedReader读卡器=新的BufferedReader(新InputStreamReader的(是));
 

我也试过这个code在Eclipse中,它的工作原理以及该文件的内容得到加载。因此,有可能需要在机器人工作室的一个步骤。

解决方案
  1. 第1步:             开放的Name_Project-Name_Project.iml文件。
  2. 看行:             选项​​名称=ASSETS_FOLDER_RELATIVE_PATH值=/ src目录/主/资产
  3. 第2步:             创建子文件夹资产主文件夹中。
  4. 第3步:             把文件这个文件夹中。
  5. 第4步:             加载它。完成。

Got a brand new project using Google's new Android Studio IDE.

I'm trying to load a simple text file using an InputStreamReader. I'm getting a file not found exception. Now there isn't any assets/ folder. I tried to create one and add my file at many different spots (at the root of the project, at the root of the .java file, etc...) I've tried to move the file around but still get the file not found.

Now that never was a problem using Eclipse as there is an assets folder created by any template.

Does anyone know where should the assets go to or how to load them?

Here is the code used, it fails at .open():

InputStream iS = resources.getAssets().open("bla.txt");
BufferedReader reader = new BufferedReader(new InputStreamReader(iS));

I also tried this code in Eclipse, it works and the file contents get loaded. So there's probably a step needed in Android Studio.

解决方案

  1. Step 1: Open in Name_Project-Name_Project.iml file.
  2. See the line : option name="ASSETS_FOLDER_RELATIVE_PATH" value="/src/main/assets"
  3. Step 2: Create a sub-folder "assets" in main folder.
  4. Step 3: Put file in this folder.
  5. Step 4: Load it. Done.

这篇关于在装载Android的工作室一个简单的文本文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆