c#读取ini文件中内容
此类利用System.Collections.Hashtable枚举INI文件中的所有设置,以便于访问。 它非常简单,并且完全可重用。 对于需要设置文件的任何应用程序来说都是可靠的补充。
using System;
using System.IO;
using System.Collections;
public class IniParser
{
private Hashtable keyPairs = new Hashtable();
private String iniFilePath;
private struct SectionPair
{
public String Section;
public String Key;
}
/// <summary>
/// Opens the INI file at the given path and enumerates the values in the IniParser.
/// </summary>
/// <param name="iniPath">Full path to INI file.</param>
public IniParser(String iniPath)
{
TextReader iniFile = null;
String strLine = null;
String currentRoot = null;
String[] keyPair = null;
iniFilePath = iniPath;
if (File.Exists(iniPath))
{
try
{
iniFile = new StreamReader(iniPath);
strLine = iniFile.ReadLine();
while (strLine != null)
{
strLine = strLine.Trim().ToUpper();
if (strLine != "")
{
if (strLine.StartsWith("[") && strLine.EndsWith("]"))
{
currentRoot = strLine.Substring(1, strLine.Length - 2);
}
&n

本文介绍如何使用C#读取和解析INI文件。通过System.Collections.Hashtable类,可以方便地枚举和访问文件中的所有设置,适用于需要配置文件的应用程序。
最低0.47元/天 解锁文章
590

被折叠的 条评论
为什么被折叠?



