problem while changing file data
uppose i have a text file as data.txt has following content such as
12.12.12.12 "www.google.com"|"www.yahoo.com"|"www.rediffmail.c om"
13.13.12.12 "www.yahoo.com"|"www.rediffmail.com"|"www.google.c om"|"www.google.com"
14.14.12.12 "www.yahoo.com"|"www.rediffmail.com"|"www.yahoo.co m"
i have another text file as token.txt has following content such as
"www.google.com" 100
"www.yahoo.com" 200
"www.rediffmail.com" 300
i want to make new file as result.txt that should contain the following data such as
12.12.12.12 100 200 300
13.13.12.12 200 300 100 100
14.14.12.12 200 300 200
my code is as follows
Code java:
import java.util.*;
import java.io.*;
public class UpdateFile
{
public static void main(String[] args) throws Exception
{
BufferedReader in=new BufferedReader(new FileReader(new File("data.txt")));
PrintWriter out=new PrintWriter(new FileWriter(new File("result.txt")));
String str="";
while((str=in.readLine())!=null)
{
ArrayList<String> url=new ArrayList<String>();
StringBuilder sq = new StringBuilder();
String parts[]=str.split("\\s+");
BufferedReader in2=new BufferedReader(new FileReader(new File("token.txt")));
String str2="";
String matchstr= parts[1];
String mm[]=matchstr.split("\\|");
for(int h =0;h<mm.length;h++){
while((str2=in2.readLine())!=null){
String urltoken[]=str2.split("\\s+");
if(mm[h] == null ? urltoken[0] == null : mm[h].equals(urltoken[0])){
if(urltoken[1].toString()!=null){
url.add(urltoken[1].toString()+"?");
}
//url.add(str2);
}
}
}
if(url.size()>0)
out.print(parts[0]+" "+" ");
for(int i=0;i<url.size();i++)
{
if(url.size()>0)
{
out.print(url.get(i));
}}
url.clear();
out.println();
out.flush();
}
}
}
Re: problem while changing file data
Please post your question in another part of the forum. This section is for introductions.
Maybe a moderator will move this to the right place.
Can you explain what your problem is? What does the program output now?
Can you explain what the program is supposed to do. It reads two files and writes out a third file.
How are the contents of the two files used to create the content of the third file?