zoukankan      html  css  js  c++  java
  • c#读入,写入文本文件

    老师留下的作业最后一条题目用到了,就百度下找到了例子修改成两个函数子程序方便使用.

            //**********************************************
            //函数名:ReadFile
            //功能:把指定文本内的数据读出并返回
            //参数: FileName文件名
            //返回值:string
            //**********************************************
            public static string ReadFile(string FileName)
            {
                StreamReader srReadFile = new StreamReader(FileName,Encoding.Default);
                string strReadLine = srReadFile.ReadToEnd(); //读取全部数据
                srReadFile.Close();
                return strReadLine; 
            }
            
            //**********************************************
            //函数名:MakeFile
            //功能:往指定文本中写入数据
            //参数: FileName文件名 Content写入内容
            //返回值:void
            //**********************************************
            public static void MakeFile(string FileName,string Content)
            {
                System.IO.StreamWriter  sw = new StreamWriter(FileName,false,Encoding.GetEncoding("gb2312"));
                try
                {
                    sw.Write(Content);
                    sw.Flush();
                }
                finally
                {
                    if ( sw != null )
                        sw.Close();
                }  
            }
  • 相关阅读:
    服务管理命令
    软件管理
    Qt软件打包与发布(windeployqt工具)
    03
    第一章 BP神经网络
    代理模式 与 Spring AOP
    java 回调机制
    HashTable 实现
    实现Singleton模式
    BST 汇总
  • 原文地址:https://www.cnblogs.com/Wzqa/p/2823258.html
Copyright © 2011-2022 走看看