/// <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. svn提交报错:svn: Aborting commit:XXXXXremains in conflict

    Svn服务器上的对应内容,在上次Update后已被别人修改了,而我也做了修改,造成冲突.先备份自己的修改,从SVN上取一份别人的修改覆盖自己的文件,然后合并自己的修改进去,最后Commit.可以先更新 ...

  2. Silverlight 中datagrid控件-- 通过设置数据虚拟化加速显示

    定义依赖属性作为datagrid的数据源 protected static readonly DependencyProperty ViewLogsProperty = DependencyPrope ...

  3. Hadoop2.2.0环境下Sqoop1.99.3安装

    本文转载自http://blog.csdn.net/liuwenbo0920/article/details/40504045 1.安装准备工作: 已经装好的hadoop环境是hadoop 2.2.0 ...

  4. 在eclipse上开发hadoop2.5.2程序的快捷方法

    本文仍然使用MapReduce的经典例子 WordCount来测试eclipse的开发环境. 与大部分教程不同的是,本文使用的hadoop是2.5.2的版本,相较于之前的0.X版本,hadoop 2. ...

  5. RecyclerView notifyDataSetChanged不起作用

    一般listview设置完data后调用notifyDataSetChanged便可刷新布局界面,然而recycleview调用这个方法却没有任何反应.对于很多不熟悉recycleview的话很容易躺 ...

  6. Delphi TcxCurrencyEditt控件说明

    金额类控件说明: AlignWithMargins:是否显示边框.由Margins 属性来设置边框的值 Anchors:控件停靠,来处理窗口最大化或是调动里的位置 AutoSize:是否自动变化大小 ...

  7. Django环境搭建

    1.安装好Python 2.7.10 2.下载解压Django Django-1.9.2.tar.gz cmd cd到解压缩目录(***) python setup.py install 3.检测是否 ...

  8. 【leetcode】 Interleaving String (hard)

    Given s1, s2, s3, find whether s3 is formed by the interleaving of s1 and s2. For example,Given:s1 = ...

  9. POJ 1681 Painter's Problem (高斯消元)

    题目链接 题意:有一面墙每个格子有黄白两种颜色,刷墙每次刷一格会将上下左右中五个格子变色,求最少的刷方法使得所有的格子都变成yellow. 题解:通过打表我们可以得知4*4的一共有4个自由变元,那么我 ...

  10. struts2截取字符串

    <struts:if test="null!=pushAd&&pushAd.length()>14"> <struts:property v ...