• c#读取文件


      string s1 = string.Empty;
                //读取文件
                try
                {

                    FileStream fs = new FileStream("F:\\test.txt", FileMode.Open);
                    StreamReader sr = new StreamReader(fs);
                    while (sr.ReadLine() != null)
                    {
                        s1 += sr.ReadLine();
                    }
                    //string s2 = sr.ReadToEnd();
                    sr.Close();
                }
                catch (Exception err)
                {

                    throw new Exception("异常信息为:" + err.Message);
                }
                finally
                {

                }
                string str1= "";
                string str;
                try
                {
                    FileStream file = new FileStream("F:\\test.txt", FileMode.Open);
                    StreamReader sr = new StreamReader(file);
                    while ((str=sr.ReadLine()) != null)
                    {
                        str1 += str;
                    }
                    //或者str = sr.ReadToEnd();
                    sr.Close();
                }
                catch
                { }

                string[] s = File.ReadAllLines("F:\\test.txt");
                //string s = textBox3.Text;
                //string[] lines = s.Split(new char[] {'\r','\n' }, StringSplitOptions.RemoveEmptyEntries);
                string[] lines = textBox3.Lines;
                int maxScore = 0;
                string Name = string.Empty;
                foreach (var line in lines)
                {
                    string[] strs = line.Split('=');
                    int score = int.Parse(strs[1]);
                    if (score > maxScore)
                    {
                        maxScore = score;
                        Name = strs[0];
                    }
                }
                label1.Text = maxScore.ToString();

           /// <summary>
           /// 写日志,方便测试,看网站需求(也可以将其写到数据库)
           /// </summary>
           /// <param name="sPath"></param>
           /// <param name="sWord"></param>
           public static void log_result(string sPath,string sWord)
           {
               StreamWriter fs = new StreamWriter(sPath, false, System.Text.Encoding.Default);
               fs.Write(sWord);
               fs.Close();
           }

  • 相关阅读:
    图解JAVA对象的创建过程
    统计机器学习
    排序算法简介及其C实现
    linux中强大的screen命令
    C语言注释
    Hello hadoop——使用hadoop进行大规模数据的全局排序
    Hadoop Streaming框架使用(二)
    shell——tr的用法
    统计学习方法《文本分类(三)》
    hadoop 常存问题
  • 原文地址:https://www.cnblogs.com/wangyhua/p/4050648.html
Copyright © 2020-2023  润新知