简体   繁体   English

无法写入:在属性文件中

[英]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 \\: 使用obj.setProperty(“ key”,“ value”)时,它传递\\:

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 谢谢Praveenkumar V

Refer the Properties class's store method API. 请参阅Properties类的存储方法API。 It says the characters #, !, =, and : are saved with escaping backslash. 它说字符#, !, =, and :以转义的反斜杠保存。

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. 如果使用Properties类中的load方法将保存的文件读回,则没有问题。 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 阅读有关该内容的javadocs: 属性

It says: 它说:

Characters that cannot be directly represented in this encoding can be written using Unicode escapes 不能使用此编码直接表示的字符可以使用Unicode转义符编写

The colon is one of these characters. 冒号是这些字符之一。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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