config.cs

来自「用C#编写的一个款搜索engine的源代码!摘自<Visual c#200」· CS 代码 · 共 96 行

CS
96
字号
using System;
using System.Text;
using System.IO;

namespace SECompare.Config
{
	public class Config
	{
		private String m_SamplingedQueryRoot;
		private String m_SampleRoot;
		private String m_DataRoot;

		public Config()
		{
			this.Load();
		}

		public String SamplingedQueryRoot
		{
			get
			{
				return this.m_SamplingedQueryRoot;
			}
			set
			{
				this.m_SamplingedQueryRoot = value;
			}
		}


		public String SampleRoot
		{
			get
			{
				return this.m_SampleRoot;
			}
			set
			{
				this.m_SampleRoot = value;
			}
		}

		public String DataRoot
		{
			get
			{
				return this.m_DataRoot;
			}
			set
			{
				this.m_DataRoot = value;
			}
		}

		public void Load()
		{
			if(!File.Exists("config.ini"))
            {
                new FileNotFoundException("Can not find config.ini");
			}

			StreamReader reader = new StreamReader("config.ini");
			String line;
			line = reader.ReadLine();
			while(line!=null)
			{
				//Skip empty line and comment line
				if(!line.Equals("")&&!line.StartsWith("#"))
				{
					//split key string and value string
					String[] splits = line.Split(new char[]{'='});
					String type = splits[0];
					if(type.Equals("SamplingedQueryRoot"))
						this.m_SamplingedQueryRoot = splits[1];
					if(type.Equals("SampleRoot"))
						this.m_SampleRoot = splits[1];
					if(type.Equals("DataRoot"))
						this.m_DataRoot = splits[1];
				}
				line = reader.ReadLine();
			}
			reader.Close();
		}

		public void Save()
		{
			FileInfo file = new FileInfo("config.ini");	
			StreamWriter w = new StreamWriter(file.FullName,false);
			w.WriteLine("SamplingedQueryRoot="+this.m_SamplingedQueryRoot);
			w.WriteLine("SampleRoot="+this.m_SampleRoot);
			w.WriteLine("DataRoot="+this.m_DataRoot);
			w.Close();
		}
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?