Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Problem with the o/p of the program  RSS feed

 
sina sinchen
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi everybody,
the code below is compiling and running properly but the output which I get is nothing but blank.My txt file looks like this:

UNIQUE-ID - RP00676
TYPES - RNA-Polymerase-Binding-Reactions
ACTIVATORS - PD00196++BS00793
OFFICIAL-EC? - T
REACTANTS - RNAP70-CPLX
REACTANTS - PM00676
//
UNIQUE-ID - RP00675
TYPES - RNA-Polymerase-Binding-Reactions
ACTIVATORS - PD00196++BS00791
OFFICIAL-EC? - T
REACTANTS - RNAP70-CPLX
REACTANTS - PM00675
//
UNIQUE-ID - RP00674
TYPES - RNA-Polymerase-Binding-Reactions
ACTIVATORS - PD00196++BS00788
OFFICIAL-EC? - T
REACTANTS - RNAP70-CPLX
REACTANTS - PM00674
//
UNIQUE-ID - RP00671
TYPES - RNA-Polymerase-Binding-Reactions
ACTIVATORS - PD00196++BS00785
OFFICIAL-EC? - T
REACTANTS - RNAP70-CPLX
REACTANTS - PM00671
//
UNIQUE-ID - RP00669
TYPES - RNA-Polymerase-Binding-Reactions
ACTIVATORS - PD00196++BS00783
OFFICIAL-EC? - T
REACTANTS - RNAP70-CPLX
REACTANTS - PM00669

CODE:
import java.io.*;
import java.util.*;
import java.lang.String.*;

public class brxns
{


public brxns() throws Exception
{
int ln=0;
String unique=" ";
String line=" ";
String [] values = new String[5];
BufferedReader b = new BufferedReader(new FileReader("E:/ecocyc/ecocyc/bindrxns.txt"));
LineNumberReader l = new LineNumberReader(b);
PrintWriter p=new PrintWriter(new BufferedWriter(new FileWriter("E:/ecocyc/ecocyc/bindingrxns.txt")));

while(true)
{
String binding_reactions = " ";
line = l.readLine();if (line==null) break;
StringTokenizer st = new StringTokenizer(line);
ln = l.getLineNumber();
if (ln>=38)
{
int i = 0;
while(st.hasMoreTokens())
{
values[i] = st.nextToken();
if(values[i]!= "UNIQUE-ID") break;
if(i==2)
{
binding_reactions =values[i];
}
i++;
}
//binding_reactions =values[2];
System.out.println(binding_reactions);
}

}

p.close();
}

Could u pls tell me where I went wrong.I want the output like:

RP00676
RP00675
RP00674
RP00671
RP00669
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Welcome to JavaRanch!

The most important problem I see here is this line:



The break will always be taken. The "!=" and "==" operators compare for reference equality -- i.e., the two operands are, or are not, the same physical object in memory. You want to compare the contents of two strings, and so you should use the equals() method:



If you don't understand the difference, have a look at this.
[ May 25, 2004: Message edited by: Ernest Friedman-Hill ]
 
sina sinchen
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanx alot for ur help. I got it.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!