码迷,mamicode.com
首页 > 其他好文 > 详细

读文本信息

时间:2014-11-27 12:20:33      阅读:179      评论:0      收藏:0      [点我收藏+]

标签:http   io   os   sp   for   on   bs   ad   ef   


public bool UserIDfromFile(string userID)
    {
        bool result = false;
        string strFileName = HttpContext.Current.Server.MapPath(@".\file") + @"\userInfo.txt";
        if (!System.IO.File.Exists(strFileName))
        {
            throw new Exception(strFileName + "打开失败!");
            result = false;
        }
        try
        {
            string strFileContents = string.Empty;
            FileStream fs = new FileStream(strFileName, FileMode.Open, FileAccess.Read);
            StreamReader reader = new StreamReader(fs, System.Text.Encoding.Default);
            strFileContents = reader.ReadToEnd();
            strFileContents.Replace("\r\n", "");
            string[] Items = strFileContents.Trim().Split(‘=‘);
            if (Items.Length >= 2)
            {
                string userinfo = strFileContents.Split(‘=‘)[1].Trim();
                string[] userIDs = userinfo.Split(‘,‘);
                for (int i = 0; i < userIDs.Length; i++)
                {
                    if (userID == userIDs[i].Trim())
                    {
                        result = true;
                    }
                }
            }
            fs.Close();
            reader.Close();
        }
        catch
        {
            result = false;
        }
        return result;
    }

读文本信息

标签:http   io   os   sp   for   on   bs   ad   ef   

原文地址:http://www.cnblogs.com/libbybyron/p/4125880.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!