如何从文本文件中获取特定行到行并在android中显示数组列表

我有一个文本文件,我能够阅读完整的内容并将其显示在视图上。 文本文件的示例示例格式: –

## userdetail [William] [Bits] 6th cross road, City house. Rio. | ## 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行文字。 所以我需要“##”下面的所有行,直到下一个“##” –

朋友请给我解决方案吗?

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

 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; } } 

使用以下代码,它可能会帮助您: –

 String sAddr=""; try { FileInputStream fileIn=c.openFileInput(LOGS_TEXT_FILE); InputStreamReader InputRead= new InputStreamReader(fileIn); char[] inputBuffer= new char[READ_BLOCK_SIZE]; int charRead; while ((charRead=InputRead.read(inputBuffer))>0) { // char to string conversion String readstring=String.copyValueOf(inputBuffer,0,charRead); sAddr +=readstring; } InputRead.close(); } catch (Exception e) { e.printStackTrace(); } String[]sAllAddrs = sAddr.split("\n"); // it would read the next line data and save it to a string. for(int i=0; i 
  InputStream inputStream = getResources().openRawResource(R.raw.storydata); BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream), 8192); try { String line_1; while ((line_1 = reader.readLine()) != null) { while ((line_1 = reader.readLine()) != null) { if(line_1.contains("##") && line_1.contains("userot")) { while ((line_1 = reader.readLine()) != null) { if(line_1.contains("##")) break; else Toast.makeText(getBaseContext(), "" +line_1, Toast.LENGTH_LONG).show(); } break; } } } } catch (IOException e) { throw new RuntimeException(e); } 

逐行阅读器文本文件….感谢Hussain Alaidarous完美的工作….