请问如何读取一个文本文件,要求一个单词一个单词的读取

解决方案 »

  1.   

    请参考:
    http://blog.csdn.net/zhangjian01361/archive/2006/11/08/1373668.aspx
      

  2.   

    /// <summary>
      /// 从文本文件中读数据,返回一个数组
      /// </summary>
      public static string[] GetTextData
      {
        get 
        {
          
          string[] result = HttpContext.Current.Cache["Ustbwuyi_ReadTextData_1.0"] as string[];
          if (result == null)
          {
            List<string> list = new List<string>();
            using(StreamReader sr=new StreamReader(HttpContext.Current.Server.MapPath("~/App_Data/Provider.txt"),Encoding.UTF8))
            {
              string str = "";
              while ((str = sr.ReadLine()) != null)
              {
                list.Add(str);
              }
              result = list.ToArray();
              HttpContext.Current.Cache.Insert("Ustbwuyi_ReadTextData_1.0", result, new System.Web.Caching.CacheDependency(HttpContext.Current.Server.MapPath("~/App_Data/Provider.txt")));
            }
          }
          return result;
        }
      }