Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: problem while changing file data

  1. #1
    Junior Member
    Join Date
    Aug 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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

    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();
     
     
        }
     
    }
    }
    Last edited by helloworld922; August 17th, 2012 at 01:57 PM. Reason: please use [code] tags


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,310
    Thanks
    56
    Thanked 2,373 Times in 2,344 Posts

    Default 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?
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. changing particular string in text file
    By cute in forum File I/O & Other I/O Streams
    Replies: 2
    Last Post: November 6th, 2011, 11:03 AM
  2. Updating TableModel if changing data on DataBase(MySQL)
    By Farrukhjon in forum AWT / Java Swing
    Replies: 2
    Last Post: September 13th, 2011, 09:59 AM
  3. Problem extracting data from file
    By hello_world in forum File I/O & Other I/O Streams
    Replies: 17
    Last Post: August 21st, 2011, 10:35 PM
  4. Replies: 8
    Last Post: March 25th, 2011, 03:34 PM
  5. Help With Java - Changing a File
    By RonenIL in forum What's Wrong With My Code?
    Replies: 0
    Last Post: January 5th, 2010, 02:34 AM