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         }
  • 相关阅读:
    [NOI2021] 路径交点
    CF1188D Make Equal
    CF1349F1 Slime and Sequences
    CF1067D Computer Game
    Dcat Admin安装
    PHP 中提示undefined index如何解决(多种方法)
    Git 常用命令大全
    项目维护环境部署
    bootstrap-table
    bootstrap-datetimepicker
  • 原文地址:https://www.cnblogs.com/hbhbice/p/1738082.html
Copyright © 2011-2022 走看看