C# 读取指定路径下的txt文件内容

/// 
        /// 获取txt文件内容
        /// 
        /// 
        /// 
        public static string GetContentByTxt(string path)
        {
            string conStr = "";
            try
            {
                FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
                StreamReader reader = new StreamReader(fs);
                conStr = reader.ReadLine();
            }
            catch (Exception)
            {
                conStr = "";
            }
            return conStr;
        }

 

你可能感兴趣的:(C# 读取指定路径下的txt文件内容)