/// <summary>
/// 将output.config内容传到app.config
/// </summary>
string ReadString;
//两个地址
string path1 = @"D:\wcf\xml文件读写\Xml_WirteOrRead\Xml_WirteOrRead\output.config";
string path2 = @"D:\wcf\xml文件读写\Xml_WirteOrRead\Xml_WirteOrRead\app.config"; /// <summary>
/// 读文件
/// </summary>
/// <param name="path"></param>
public void ReadFile(string path)
{
try
{
FileStream afile = new FileStream(path, FileMode.Open);
StreamReader sread = new StreamReader(afile);
//ReadString = sread.ReadLine();
ReadString = sread.ReadToEnd();
sread.Close();
afile.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
} /// <summary>
/// 写文件
/// </summary>
public void WriteFile()
{
try
{
FileStream afile = new FileStream(path2, FileMode.OpenOrCreate);
StreamWriter swrite = new StreamWriter(afile);
if (!string.IsNullOrEmpty(ReadString))
{
swrite.Write(ReadString);
// swrite.WriteLine(ReadString);
}
swrite.Close();
afile.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}

C# 对于文件的读取与写入!!个人做的一个小例子!

C# 文件读取方法,自己写的例子,保存一下,备用的更多相关文章

  1. 大文件读取方法(C#)

    之前都是用StreamReader.ReadLine方法逐行读取文件,自从.NET4有了File.ReadLines这一利器,就再也不用为大文件发愁了. File.ReadLines在整个文件读取到内 ...

  2. python 文件读取方法详解

    话不多说直接码 # 绝对路径 # f = open('/Users/fangxiang/Downloads/我的古诗.text', mode='r', encoding='utf-8') # cont ...

  3. 文件读取方法(FileHelpers) z

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using FileHelp ...

  4. C# 读写XML文件的方法

    C# 读写XML文件的方法 一.写XML文件 XmlDocument xmlDocument = new XmlDocument();xmlDocument.AppendChild(xmlDocume ...

  5. springboot-项目获取resources下文件的方法

    spring项目获取resources下文件的方法   最近写读取模板文件做一些后续的处理,将文件放在了项目的resources 下,发现了一个好用的读取方法:   比如上边是你需要读取的文件:  读 ...

  6. golang 文件读取

    Golang 的文件读取方法很多,刚上手时不知道怎么选择,所以贴在此处便后速查. 一次性读取 小文件推荐一次性读取,这样程序更简单,而且速度最快. 复制代码 代码如下: func ReadAll(fi ...

  7. Javascript写入txt和读取txt文件的方法

    文章主要介绍了Javascript写入txt和读取txt文件的方法,需要的朋友可以参考下1. 写入 FileSystemObject可以将文件翻译成文件流. 第一步: 例: 复制代码 代码如下: Va ...

  8. 分享:Perl打开与读取文件的方法

    在Perl中可以用open或者sysopen函数来打开文件进行操作,这两个函数都需要通过一个文件句柄(即文件指针)来对文件进行读写定位等操作. Perl打开与读取文件的方法,供大家学习参考.本文转自: ...

  9. PCB 无需解压,直接读取Genesis TGZ指定文件 实现方法

    通过无需解压读取ZIP压缩包的方法,寻思者如何可以不解压直接读Genesis TGZ文件内容, 通过查找资料,原来可以通过:SharpCompress.dll工具实现此需求,此工具如此NB 一.Sha ...

随机推荐

  1. 深度分析Linux下双网卡绑定七种模式 多网卡的7种bond模式原理

    http://blog.csdn.net/abc_ii/article/details/9991845多网卡的7种bond模式原理 Linux网卡绑定mode共有七种(~) bond0.bond1.b ...

  2. VS中计算程序运行时间

    VS中计算程序运行的时间   http://bbs.csdn.net/topics/39068881 有时候在设计程序完了之后需要计算程序运行的时间. 这时候可以使用Windows的库函数 GetIi ...

  3. spring + myBatis 常见错误:SQL语法错误

    在程序运行时,有时候会出现如下错误: 这个错误通常是你的sqlmapper.xml中sql语句语法有错误.所以请仔细查看你sql语句是否正确,比如{#id}这样写就会报上述错误,其实应该#{id}这样 ...

  4. 去掉mysql数据库字段中的个别字符

     update 表名 set 列名 = REPLACE (mcategory,"要去掉的字符","") where 列名 like "%要去掉的字符% ...

  5. [转]AndroidStudio导出jar包

    原文链接:http://blog.csdn.net/hjq842382134/article/details/38538097# 1. 不像在Eclipse,可以直接导出jar包.AndroidStu ...

  6. ubuntu apc 安装

    在ubuntu下安装APC,只需要两条命令,便可将APC和php绑一起.     安装代码:          sudo apt-get install  -y apache2-prefork-dev ...

  7. OKhttp基本使用介绍

    MainActivity.class package com.example.administrator.okhttp3; import android.support.v7.app.AppCompa ...

  8. 用户登录流程详解 +volley(StringRequest)

    在实习期间由于要求使用volley,所以第一次开始接触volley,从一开始的迷茫陌生,到疯狂的查找各种资料,通过在项目中用到的实际问题,我想做一些总结,所以写了这篇文章.下面我将介绍我理解的用户登录 ...

  9. 【leetcode】Number of Islands(middle)

    Given a 2d grid map of '1's (land) and '0's (water), count the number of islands. An island is surro ...

  10. python2.7之MySQLdb模块 for linux安装

    1.下载:MySQL-pythonhttp://sourceforge.net/projects/mysql-python/files/mysql-python-test/1.2.3b1/MySQL- ...