Home > php教程 > php手册 > body text

c#读取文件写文件

WBOY
Release: 2016-06-06 20:00:59
Original
1200 people have browsed it

/// summary /// 读文件方法 /// /summary /// param name="filename"文件名/param /// returns文件内容/returns private string ReadFile(string filename) { string str = ""; string filenamepath = filename; //打开文件 StreamReader sr = File.OpenTex

     ///


    /// 读文件方法
    ///

    /// 文件名
    /// 文件内容
    private string ReadFile(string filename)
    {
        string str = "";
        string filenamepath = filename;
        //打开文件
        StreamReader sr = File.OpenText(filenamepath);
        str = sr.ReadToEnd();
        sr.Close();
        return str;
    }

    ///


    /// 写文件方法
    ///

    /// 文件名
    /// 文件内容
    public void WriteFile(string Path, string Strings)
    {
        StreamWriter sw = null;

        try
        {
            sw = new StreamWriter(Path, false, System.Text.Encoding.UTF8);
            sw.Write(Strings);
            sw.Flush();
        }
        catch (Exception exp)
        {
            HttpContext.Current.Response.Write(exp.Message);
            HttpContext.Current.Response.End();
        }
        finally
        {
            sw.Close();
        }
    }

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!