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

查看:54
本文介绍了如何从文本文件中获取特定行并在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 行

但我的要求是我需要从字段名称中获取特定数据.我可以获得所有唯一 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 "##" –

朋友请给我解决方案?

推荐答案

下面的解决方案是找到'## 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天全站免登陆