Hi Vijaya,
The way I'd approach this would normally be to use (*nix) shell scripting (diff && wget spring to mind). Or even better use proper version control like CVS.
If you need to use java, here's a possible approach.
First, make a class that reads a URL into an array. This one is slightly complex and you'd probably be better to use a Vector rather than a String Array so you don't have all the complex array copies (actually wouldhave been better to use System.arrayCopy(), but this is kinda old code):
Code:
import java.net.*;
import java.util.*;
import java.io.*;
/**
*@author Charlie
*@created 06 September 2001
*@description Read a file from a URL, and return in as an array
*/
public class FileToArray {
String[] linesToReturn;
String urlString = new String();
public FileToArray(URL textURL) {
String urlString = new String(textURL.toString());
linesToReturn = new String[20];
String[] swap;
String line = new String("");
try {
BufferedReader theStream = new BufferedReader(new InputStreamReader(textURL.openStream()));
int index = 0;
while ((line = theStream.readLine()) != null) {
if (index == linesToReturn.length) {//array needs to grow
swap = linesToReturn;
linesToReturn = new String[linesToReturn.length * 2];
for (int i = 0; i < swap.length; i++) {
linesToReturn[i] = swap[i];
}
}
linesToReturn[index] = line;
index++;
}
theStream.close();
} catch (Exception e) {
linesToReturn[0] = "File i/o error\n" + e.toString();
}
//Shrink the array down
int howManyNonNulls = 0;
swap = linesToReturn;
for (int x = 0; x < swap.length; x++) {
if (linesToReturn[x] != null)
howManyNonNulls++;
}
linesToReturn = new String[howManyNonNulls];
for (int y = 0; y < linesToReturn.length; y++) {
linesToReturn[y] = swap[y];
}
}
public String[] getLines() {
return linesToReturn;
}
}
OK now you'va abstracted the reading stuff into an array out, all you need to do is:
- read list of urls from a file into a String[],
- compare the contents of each line in the String[] to a corresponding line in the file on your local filesystem
I'll let you figure out how to compare between arrays (it's a tricky one, and you may want to use regexps). This version just prints out the contents of exch url in the file d:/jclasses/url-list.txt.
Code:
public class readLinks {
public static void main(String[] argv) {
try {
FileToArray linkFile = new FileToArray(new URL("file://d:/jclasses/url-list.txt"));
String[] urls = linkFile.getLines();
for (int i = 0; i < urls.length; i++) {
FileToArray url = new FileToArray(new URL(urls[i]));
String[] lines = url.getLines();
for (int j = 0; j < lines.length; j++)
System.out.println(lines[j]);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
HTH charlie
--
Don't Stand on your head - you'll get footprints in your hair.
http://charlieharvey.com