[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
希望从这个文本文件中查找name: ******变量,如name: in silico,读取出其上一行的MI:0491,怎么才能做到啊?谢谢了
7 个解决方案
#1
先把文件读到内存里面,然后用正则表达式匹配可行不?
#2
关键读出来的是上一行中的几个字符呢
#3
BufferedReader br = new BufferedReader(new FileReader(new File(path)));
String line1,line2,line;
while ((line= br.readLine()) != null) {
line1=line2;
line2=line;
if("name: in silico".equals(line2)){
break;
}
}
if(line1!=null){
System.out.println(line1);
}
自己加上比较时的trim
String line1,line2,line;
while ((line= br.readLine()) != null) {
line1=line2;
line2=line;
if("name: in silico".equals(line2)){
break;
}
}
if(line1!=null){
System.out.println(line1);
}
自己加上比较时的trim
#4
BufferedReader br = new BufferedReader(new FileReader(new File(path)));
String line1,line2,line;
boolean bln;
while ((line= br.readLine()) != null) {
line1=line2;
line2=line;
if("name: in silico".equals(line2)){
bln=true;
break;
}
}
if(line1!=null && bln){
System.out.println(line1);
}
楼上写错了。
String line1,line2,line;
boolean bln;
while ((line= br.readLine()) != null) {
line1=line2;
line2=line;
if("name: in silico".equals(line2)){
bln=true;
break;
}
}
if(line1!=null && bln){
System.out.println(line1);
}
楼上写错了。
#5
最近再看groovy,用它做这种事情是很方便的,只要1行代码:
new File ('c:/somefile.txt').eachLine {if (it=~/name:\.*/) println preLine; preLine = it}
#6
4楼的。.
你的代码有问题哦
line1,lin2,line
3个变量都没说清楚哦,
你想的是让他们调换,可根本就不行嘛,那能简单的就来个line1=line2,line2=line了事?
你怎么知道line1就是上一行呢?
你的代码有问题哦
line1,lin2,line
3个变量都没说清楚哦,
你想的是让他们调换,可根本就不行嘛,那能简单的就来个line1=line2,line2=line了事?
你怎么知道line1就是上一行呢?
#7
修改一下4楼的:
String path="xxxxx";
BufferedReader br = new BufferedReader(new FileReader(new File(path)));
String line1,line2,line;
while ((line= br.readLine()) != null) {
line1=line2;
line2=line;
if("name: in silico".equals(line2)){
if(line1.indexOf("MI:0491"!=-1)
System.out.println(line1);
}
String path="xxxxx";
BufferedReader br = new BufferedReader(new FileReader(new File(path)));
String line1,line2,line;
while ((line= br.readLine()) != null) {
line1=line2;
line2=line;
if("name: in silico".equals(line2)){
if(line1.indexOf("MI:0491"!=-1)
System.out.println(line1);
}
#1
先把文件读到内存里面,然后用正则表达式匹配可行不?
#2
关键读出来的是上一行中的几个字符呢
#3
BufferedReader br = new BufferedReader(new FileReader(new File(path)));
String line1,line2,line;
while ((line= br.readLine()) != null) {
line1=line2;
line2=line;
if("name: in silico".equals(line2)){
break;
}
}
if(line1!=null){
System.out.println(line1);
}
自己加上比较时的trim
String line1,line2,line;
while ((line= br.readLine()) != null) {
line1=line2;
line2=line;
if("name: in silico".equals(line2)){
break;
}
}
if(line1!=null){
System.out.println(line1);
}
自己加上比较时的trim
#4
BufferedReader br = new BufferedReader(new FileReader(new File(path)));
String line1,line2,line;
boolean bln;
while ((line= br.readLine()) != null) {
line1=line2;
line2=line;
if("name: in silico".equals(line2)){
bln=true;
break;
}
}
if(line1!=null && bln){
System.out.println(line1);
}
楼上写错了。
String line1,line2,line;
boolean bln;
while ((line= br.readLine()) != null) {
line1=line2;
line2=line;
if("name: in silico".equals(line2)){
bln=true;
break;
}
}
if(line1!=null && bln){
System.out.println(line1);
}
楼上写错了。
#5
最近再看groovy,用它做这种事情是很方便的,只要1行代码:
new File ('c:/somefile.txt').eachLine {if (it=~/name:\.*/) println preLine; preLine = it}
#6
4楼的。.
你的代码有问题哦
line1,lin2,line
3个变量都没说清楚哦,
你想的是让他们调换,可根本就不行嘛,那能简单的就来个line1=line2,line2=line了事?
你怎么知道line1就是上一行呢?
你的代码有问题哦
line1,lin2,line
3个变量都没说清楚哦,
你想的是让他们调换,可根本就不行嘛,那能简单的就来个line1=line2,line2=line了事?
你怎么知道line1就是上一行呢?
#7
修改一下4楼的:
String path="xxxxx";
BufferedReader br = new BufferedReader(new FileReader(new File(path)));
String line1,line2,line;
while ((line= br.readLine()) != null) {
line1=line2;
line2=line;
if("name: in silico".equals(line2)){
if(line1.indexOf("MI:0491"!=-1)
System.out.println(line1);
}
String path="xxxxx";
BufferedReader br = new BufferedReader(new FileReader(new File(path)));
String line1,line2,line;
while ((line= br.readLine()) != null) {
line1=line2;
line2=line;
if("name: in silico".equals(line2)){
if(line1.indexOf("MI:0491"!=-1)
System.out.println(line1);
}