如何获得特定的线路从Android中的文本文件,并显示数组列表行 [英] How to get particular line to line from text file and display array list in android

查看:291
本文介绍了如何获得特定的线路从Android中的文本文件,并显示数组列表行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个文本文件,我是能够阅读完整内容并在视图中显示它。
对于文本文件样本示例格式: -

I have a text file, and i was able to read the full content and display it on a view. Sample example format for text file :-

## userdetail 

   [William]
   [Bits]
   6th cross road, City house.
   Rio.
   <051-22345690>|<002-22345690>

## calldetails

    income 22.
    out going 24.
    missed 21.


## Lorempsum
 Lorem Ipsum is simply dummy text of the printing and typesetting industry. 
 Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, 
 when an unknown printer took a galley of type and scrambled it to make a type specimen book 


## userot 
 It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout.                  

...........
...........
...........

........... ........... ...........

它更喜欢50行

但我的要求是,我需要从外地names.I获取特定数据可以得到所有的唯一ID的## userot的价值。但是,我需要的数据在两者之间没有哈希映射的细节。
数据有时也可在下一行了。我是说,在某些情况下,我有5行,
其他的有10行文字。所以,我需要以下的所有行##到明年## -

But my requirement is I need to get particular data from the field names.I can get "## userot" value of all unique ids. But I require the details of in-between data without hash-mapping. the data sometimes are also in the next line too. I Mean, on some case i have 5 lines, on other in have 10 lines of text. So I need all the lines below "## " till next "##" –

朋友请给我的解决方案呢?

friend please give me solution for it ?

推荐答案

解决方案下面是找到后,## userot的所有行,直到下一个##

The solution below is find all the lines after '## userot' until the next ##

FileInputStream fileIn = openFileInput("mytextfile.txt");
InputStreamReader inputRead = new InputStreamReader(fileIn);
BufferedReader reader = new BufferedReader(inputRead);

while ((str = reader.readLine()) != null){
    if(str.contains("##") && str.contains("userot"){
        while ((str = reader.readLine()) != null){
            if(str.contains("##"))
              break;
            else
              Log.d("TAG","output: " + str);
        }
        break;
     }
}

这篇关于如何获得特定的线路从Android中的文本文件,并显示数组列表行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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