Download it:
Properties properties = new Properties(); properties.load(your_reader);
Then use the remove () method to remove the property:
properties.remove(your_key);
And finally, write this change to the file properties file:
properties.store(your_writer, null);
UPDATE
I am posting this update after your comment:
I tried .. what I get does not interfere with the older content .. just rewrote the file again with the value deleted .. initially the file had key1 = value1 and key2 = value2 .. using the above code, I tried to delete key2, now the file has key1 = value1 key2 = value2, and then today's time and date after that key1 = value1
Try this example, I tried, and it works fine, I think you have some error in the code if it doesn't work:
import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.OutputStream; import java.util.Properties; public class Props { public Props() { try { File myFile = new File("props.properties"); Properties properties = new Properties(); properties.load(new FileInputStream(myFile)); properties.remove("deletethis"); OutputStream out = new FileOutputStream(myFile); properties.store(out, null); } catch (Exception e) { e.printStackTrace(); } } public static void main(String[]args){ new Props(); } }
props.properties to :
props.properties after :
source share