I am trying to tackle a program take the given input file is in.properties and I want to write it out again to a new file out.properties discarding the prefix prefix from the file contents
i.e. the contents of the input file would be
prefix.sum.code.root=/compile/pkg
the contents of the output file would be
sum.code.root=/compile/pkg
Here is my Code :
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Properties;
public class Dummy {
public static void main(String args[])
{
Properties prop =new Properties();
try{
//load a property file
prop.load(new FileInputStream ("C:\\Users\\user\\Desktop\\ant\\Filtering\\input.properties"));
for (String key : prop.stringPropertyNames()){
prop.remove(key);
}
prop.store(new FileOutputStream("C:\\Users\\user\\Desktop\\ant\\Filtering\\output.properties"), null);
}catch (IOException e)
{
e.printStackTrace();
}
}}
The returning null value for the ‘KEY’ and i am not able to update new value into this feild
You should be able to do this fairly easy using
Properties.stringPropertyNamesandHashtable.remove, asPropertiesis a subclass ofHashtable.