zoukankan      html  css  js  c++  java
  • 打开一个文本文件

     1            //打开一个文本文件
     2             if (openFileDialog1 .ShowDialog ()== DialogResult .OK )
     3             {
     4                 string file = openFileDialog1.FileName;
     5                 //如果不加 Encoding.Default,那么StreamReader默认编码为Unicode(UTF-8)
     6                 StreamReader sr = new StreamReader(file); 
     7 
     8                 ////增加一System.Text.Encoding.Default 则不传会出现乱码。, System.Text.Encoding.Default
     9                 //StreamReader sr = new StreamReader(file,Encoding .Default );  
    10                 
    11                 //显示当前流的字符编码
    12                 //MessageBox.Show(sr.CurrentEncoding.EncodingName);
    13                 
    14                 string s = sr.ReadLine();
    15                 
    16                 while (s != null)
    17                 {
    18                     textBox1.AppendText(s + "\r\n");
    19                     s = sr.ReadLine();
    20       
    21                 }
    22                 sr.Close();
    23             }
    24         }
  • 相关阅读:
    poj 2485 Highways 最小生成树
    hdu 3415 Max Sum of MaxKsubsequence
    poj 3026 Borg Maze
    poj 2823 Sliding Window 单调队列
    poj 1258 AgriNet
    hdu 1045 Fire Net (二分图匹配)
    poj 1789 Truck History MST(最小生成树)
    fafu 1181 割点
    减肥瘦身健康秘方
    人生的问题
  • 原文地址:https://www.cnblogs.com/hbhbice/p/1738082.html
Copyright © 2011-2022 走看看