• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

whats wrong with this code

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
the code bel�ow is compiling and executing without any errors but i couldnot get the expected output.MY input files gene1 and gene2 are as below:

gene1:
EG20012345
EG10023456
EG40025689
EG30036589
EG50012457

gene2:
arg EG100
pdr EG200
frd EG300
fed EG400
fre EG500


import java.io.*;
import java.util.*;
import java.lang.String.*;
public class findreplace
{


public findreplace() throws Exception
{
int ln=0;int ln1=0;
String line=" ";String line1=" ";
String value[] =new String[200];
String values[] =new String[200];
BufferedReader b = new BufferedReader(new FileReader("E:/gene2.txt"));
LineNumberReader l = new LineNumberReader(b);
PrintWriter p=new PrintWriter(new BufferedWriter(new FileWriter("E:/gene3.txt")));
//System.out.println("RMSICA" + "\t"+"Rank"+"\t"+"Consensus Score");
//p.println("BR"+"\t"+"REACTANTS" );
while(true)
{
line = l.readLine();if (line==null) break;
StringTokenizer st = new StringTokenizer(line);
ln = l.getLineNumber();
if (ln>=1)
{
int i = 0;
while(st.hasMoreTokens())
{
value[i] = st.nextToken();//p.println(values[i]);

//if(values[0].equals("UNIQUE-ID"))
if(i==1)
{
BufferedReader b1 = new BufferedReader(new FileReader("E:/gene1.txt"));
LineNumberReader l1 = new LineNumberReader(b1);
while(true)
{
line1 = l1.readLine();if (line1==null) break;
StringTokenizer st1 = new StringTokenizer(line1);
ln1 = l1.getLineNumber();
if (ln1>=1)
{
int i1 = 0;
while(st1.hasMoreTokens())
{
values[i1] = st1.nextToken();
if (value[1].equals(values[0]))
if(i1==1)
p.println();
p.print("replaced file");
p.print(value[0]+"\t"+value[1]+"\t"+values[1]);
}

i1++;
}


}

}
}
i++;
}
}

p.close();
}
public static void main(String s[]) throws Exception
{
new findreplace();
}
}

My expected output:

Gene3(file):
arg EG100 23456
pdr EG200 12345
frd EG300 36589
fed EG400 25689
fre EG500 12457.

thanx in advace,
regards,
Bobby
 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

try this one. In general it's your Code I have taken only small changes.
Perhaps it's not the best way to code that but it will work.

Have fun with.


import java.io.*;
import java.util.*;
import java.lang.String.*;
public class findreplace
{


public findreplace() throws Exception
{
int ln=0;int ln1=0;
String line=" ";String line1=" ";
String value[] =new String[200];
String values[] =new String[200];

BufferedReader b = new BufferedReader(new FileReader("E:/gene2.txt"));
LineNumberReader l = new LineNumberReader(b);

PrintWriter p=new PrintWriter(new BufferedWriter(new FileWriter("E:/gene3.txt")));

while(true)
{
line = l.readLine();if (line==null) break;
StringTokenizer st = new StringTokenizer(line);
ln = l.getLineNumber();
if (ln>=1)
{
int i = 0;
while(st.hasMoreTokens())
{
value[i] = st.nextToken();

if(i==1)
{
BufferedReader b1 = new BufferedReader(new FileReader("E:/gene1.txt"));
LineNumberReader l1 = new LineNumberReader(b1);
while(true)
{
line1 = l1.readLine();if (line1==null) break;

StringTokenizer st1 = new StringTokenizer(line1);
ln1 = l1.getLineNumber();

if (ln1>=1)
{
int i1 = 0;
while(st1.hasMoreTokens())
{
values[i1] = st1.nextToken();
i1++;
}

if (value[1].equals(values[0]))
{
p.println();
p.print(value[0]+"\t"+value[1]+"\t"+values[1]);
}

}

}
}
i++;
}
}
}

p.close();
}

public static void main(String s[]) throws Exception
{
new findreplace();
}
}
 
sinchen kutty
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanx alot,i have fixed the problem.
 
reply
    Bookmark Topic Watch Topic
  • New Topic