简体   繁体   中英

Not able to write : in Property file

In my application user can change the propery file.. But that text contains : colon. While using obj.setProperty("key","value") it passes \\:

Please find the below example code and do needful.

String url="http://google.co.in";
Properties p=new Properties();
FileOutputStream o=new FileOutputStream("abc.properties");
p.setProperties("testurl",url);
p.store(o,null);
o.close();

Thank you Praveenkumar V

Refer the Properties class's store method API. It says the characters #, !, =, and : are saved with escaping backslash.

The key and element characters #, !, =, and : are written with a preceding backslash to ensure that they are properly loaded.

If you read the saved file back with load method in Properties class, there is no problem. If not, you'll have to write your own custom code to escape these characters while loading.

That's the normal behavior of the class. Read the javadocs for that: Properties

It says:

Characters that cannot be directly represented in this encoding can be written using Unicode escapes

The colon is one of these characters.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM