您的位置:首页 > 编程语言 > C#

C#——读写ini文件

2016-07-20 11:26 429 查看
namespace JF_SJ.Services

{

    public class InIWriteAndRead

    {

        [System.Runtime.InteropServices.DllImport("kernel32")]

        private static extern long WritePrivateProfileString(string section, string key, string val, string filePath);

        [System.Runtime.InteropServices.DllImport("kernel32")]

        private static extern int GetPrivateProfileString(string section, string key, string def, System.Text.StringBuilder retVal, int size, string filePath);

        public static void INIWrite(string section, string key, string value, string sPath)

        {

            // section=配置节,key=键名,value=键值,path=路径

            WritePrivateProfileString(section, key, value, sPath);

        }

        public static string INIReade(string section, string key, string sPath)

        {

            // 每次从ini中读取多少字节

            System.Text.StringBuilder temp = new System.Text.StringBuilder(255);

            // section=配置节,key=键名,temp=上面,path=路径

            GetPrivateProfileString(section, key, "", temp, 255, sPath);

            return temp.ToString();

        }

    }
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: