从文件中读取的资产文本 [英] reading Text from file in assets

查看:133
本文介绍了从文件中读取的资产文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的test.txt叫资产文件夹中的文本文件。它包含以下形式的字符串

i have an text file in my assets folder called test.txt. It contains a string in the form

项目1,项目2,项目3

"item1,item2,item3

我如何阅读文本和阵列,这样我就可以举杯由逗号deliminated三个项目中的任何一个
在这里读书后加载文件的方式后如下:

How do i read the text into and array so that I can then toast any one of the three items that are deliminated by a comma After reading post here the way to load the file is as follows

AssetManager assetManager = getAssets();
InputStream ims = assetManager.open("test.txt");

但不能工作,如何进入一个数组

But cant work out how to get into an array

您的帮助是AP preciated

your help is appreciated

标记

推荐答案

这是一个方法:

         InputStreat inputStream = getAssets().open("test.txt");
         ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();

         int i;
      try {
       i = inputStream.read();
       while (i != -1)
          {
           byteArrayOutputStream.write(i);
           i = inputStream.read();
          }
          inputStream.close();
      } catch (IOException e) {
       // TODO Auto-generated catch block
       e.printStackTrace();
      }

    String[] myArray = TextUtils.split(byteArrayOutputStream.toString(), ",");

这篇关于从文件中读取的资产文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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