JAVA读取文件中特定字符串后面的值 各位高手,我有一个文本文件,格式基本上是这样的:
[Term]
id: MI:0491
name: in silico
def: "Results generated by predictive bioinformatics approaches rather than experimental data.\nOBSOLETE as a full host organisms description is recommended using tax id == -1 as convention to refer to 'in vitro' interaction." [PMID:14755292]
related_synonym: "Predictive" []
is_obsolete: true
[Term]
id: MI:0489
name: source database
def: "Database that orignally provided the interaction record for exchange purposes." [PMID:14755292]
is_a: MI:0444 ! database citation
希望从这个文本文件中查找到每个[Term]中各个变量值如:得到name的值in silico,并将每个[Term]的各个变量记录下来
------最佳解决方案-------------------- 测试文件同上;
import java.util.*;
import java.io.*;
public class Test2
{
public static void main(String[] args) throws Exception{
BufferedReader br = null;
boolean start = false;
int num = 0;
List<String> array = new ArrayList<String>();
try{
br = new BufferedReader(new FileReader("test.txt"));
String s = null;
while((s = br.readLine().trim()) != null){
if(s.equals("[Term]")){
num++;
start = true;
}else if(num%2==0){
start =false;
num = 0;
}else if(start){
String[] str = s.split(":",2);
array.add(str[0]);
System.out.println(s);
//6楼能不能说下结果阈值的具体用法,是否表示分成两段
//我对API例子中的其它数值不大理解。
}
}