Can .NET load and parse a properties file equivalent to Java Properties class?

前端 未结 13 1669
死守一世寂寞
死守一世寂寞 2020-12-01 01:19

Is there an easy way in C# to read a properties file that has each property on a separate line followed by an equals sign and the value, such as the following:



        
13条回答
  •  Happy的楠姐
    2020-12-01 01:40

    Most Java ".properties" files can be split by assuming the "=" is the separator - but the format is significantly more complicated than that and allows for embedding spaces, equals, newlines and any Unicode characters in either the property name or value.

    I needed to load some Java properties for a C# application so I have implemented JavaProperties.cs to correctly read and write ".properties" formatted files using the same approach as the Java version - you can find it at http://www.kajabity.com/index.php/2009/06/loading-java-properties-files-in-csharp/.

    There, you will find a zip file containing the C# source for the class and some sample properties files I tested it with.

    Enjoy!

提交回复
热议问题