乐乐

乐乐的博客园
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

How to read/write ini file

Posted on 2007-06-29 09:59  带你去月球  阅读(251)  评论(0编辑  收藏  举报
public class IniFile
    
{
        
//ini文件的路径   
        [DllImport("kernel32")]
        
private static extern long WritePrivateProfileString(string section, string key, string val, string filepath);
        [DllImport(
"kernel32")]
        
private static extern int GetPrivateProfileString(string section, string key, string def, StringBuilder retVal, int size, string filepath);

        
public IniFile() // ctor function
        {

        }


        
//写ini文件   
        public void IniWriteValue(string Section, string Key, string Value, string inipath)
        
{
            WritePrivateProfileString(Section, Key, Value, inipath);
        }


        
//读ini文件   
        public string IniReadValue(string Section, string Key, string inipath)
        
{
            
int buffer;
            buffer 
= 255;//定义长度
            StringBuilder temp = new StringBuilder(buffer);
            GetPrivateProfileString(Section, Key, 
"", temp, buffer, inipath);
            
return temp.ToString();
        }


    }
无觅相关文章插件,快速提升流量