Regarding Appending files..
Hello Everyone,
Here I ve a code which lists the keys that are not found between two
properties files and writes that to a log file named
KeysNotFound.log...
now each time,when i compile by changing the property file to be
compared with a standard property file,it overwrites the existing log
file and writes the latest compiled version..
so what i want to know is, the last compiled version has to be appended
to the previous compiled..so if i ve compiled using 4 property files,
say, then all the four has to be appended to the same log file in
sequence..please can you people help me?
Thanks in Advance,
Megha.
import java.io.*;
import java.util.*;
import java.lang.*;
class DirFile{
public static void main(String args[]){
Properties properties1 = new Properties();
Properties properties2 = new Properties();
Properties properties3 = new Properties();
String dirname = "/Properties Files";
File f1 = new File(dirname);
if(f1.isDirectory()){
System.out.println("Directory of " +dirname);
String s[] = f1.list();
for(int i=0;i<s.length;i++){
File f = new File(dirname +s[i]);
if(f.isDirectory()){
System.out.println(s[i] + " is a directory");
}
else{
System.out.println(s[i] + " is a file");
}
}
}
else{
System.out.println(dirname + " is not a directory");
}
try{
properties1.load(new FileInputStream("FileNames.properties"));
}
catch(IOException e){
}
Enumeration enumeration = properties1.propertyNames();
String str,str1,str2,str3;
while(enumeration.hasMoreElements()){
str =(String)enumeration.nextElement();
System.out.println(str);
}
str1 = properties1.getProperty("ReferenceFile");
str2 = properties1.getProperty("File1");
System.out.println("The keyValue for File1 is: " +str1);
System.out.print("The keyValue for ReferenceFile is: " +str2);
try{
properties2.load(new FileInputStream(str1));
properties3.load(new FileInputStream(str2));
}
catch(IOException e){
}
try{
BufferedWriter buffwriter = new BufferedWriter(new
FileWriter("KeysNotFound.log"));
Date date = new Date(System.currentTimeMillis());
System.out.println("\n" +date + "\n");
Enumeration enumeration1 = properties2.propertyNames();
while(enumeration1.hasMoreElements()){
str3 =(String)enumeration1.nextElement();
String value2 = properties3.getProperty(str3);
if(value2 == null){
System.out.println(" " + "Key not found :" +str3);
buffwriter.write("\n" + "[" +date + "]" +str3 );
}
}
buffwriter.close();
}
catch(IOException e){
}
}
}