在特定单词后开始读取文件 [英] Start reading the file after a specific word

查看:157
本文介绍了在特定单词后开始读取文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含一些信息的文本文件,看起来如下所示。
我应该在特定单词出现后读取文件(完整填充),并将每个行中垂直对齐的值存储在数组中(也可以是arraylist)

I have a text file with some information in it, which looks something like displayed below. I'm supposed to read the file after a specific word occurs (Complete Population), and store the vertically aligned values in each line like in an array (could be arraylist too)

文件的样子 -

What the file looks like -

Tue May 14 08:27:25 EST 2013 
mating_pool=80
mutation_dist=3
algo_name=ARMO

完整人口

8.78792396E8 7.45689508E8 8.37899916E8 9.52778502E8 8.47061622E8 
8.80017166E8 7.50224432E8 8.23658404E8 9.51664198E8 8.49145008E8 
8.85724416E8 7.48191542E8 7.61295532E8 1.00892758E9 8.52389824E8 
8.96069156E8 7.11234404E8 7.68007126E8 9.7238065E8 8.5759227E8 
8.96193522E8 7.11177522E8 7.67777526E8 9.72449466E8 8.5763106E8 
8.95546766E8 7.1112849E8 7.68311754E8 9.71998374E8 8.57960886E8 
8.95480802E8 7.11023308E8 7.68223532E8 9.72097758E8 8.5803376E8
8.9549393E8 7.11015392E8 7.68194136E8 9.72079838E8 8.5804897E8 
8.95467666E8 7.11364074E8 7.68318732E8 9.7189094E8 8.58053462E8 
8.95574386E8 7.11095656E8 7.68187948E8 9.71985272E8 8.58095624E8 
8.95390774E8 7.11052654E8 7.684207E8 9.72098718E8 8.58105648E8 

我尝试了什么

我能读懂只有一行数字,不知道如何垂直添加数字

任何帮助表示赞赏。

推荐答案

嗯,实际上这里没有问题。你只需要编码就可以了。
这里有一些很好的代码螺纹
执行以下操作:

Well, there actually is no issue here. You just need to code it. There are some nice pieces of code in this thread. Do something like this:

 BufferedReader br = new BufferedReader(new FileReader(file));
 String line;
 while ((line = br.readLine()) != null) {
  if (line.contains("Complete Population"){
    // do something
    break; // breaks the while loop
  }
 }

 // we reached the section with numbers
 while ((line = br.readLine()) != null) {
    // use String.split to split the line, then convert 
    //the values to double and process them.  
 }

}

br.close();

br.close();

这篇关于在特定单词后开始读取文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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