C# 文件读取方法,自己写的例子,保存一下,备用
/// <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# 文件读取方法,自己写的例子,保存一下,备用的更多相关文章
- 大文件读取方法(C#)
之前都是用StreamReader.ReadLine方法逐行读取文件,自从.NET4有了File.ReadLines这一利器,就再也不用为大文件发愁了. File.ReadLines在整个文件读取到内 ...
- python 文件读取方法详解
话不多说直接码 # 绝对路径 # f = open('/Users/fangxiang/Downloads/我的古诗.text', mode='r', encoding='utf-8') # cont ...
- 文件读取方法(FileHelpers) z
using System; using System.Collections.Generic; using System.Linq; using System.Text; using FileHelp ...
- C# 读写XML文件的方法
C# 读写XML文件的方法 一.写XML文件 XmlDocument xmlDocument = new XmlDocument();xmlDocument.AppendChild(xmlDocume ...
- springboot-项目获取resources下文件的方法
spring项目获取resources下文件的方法 最近写读取模板文件做一些后续的处理,将文件放在了项目的resources 下,发现了一个好用的读取方法: 比如上边是你需要读取的文件: 读 ...
- golang 文件读取
Golang 的文件读取方法很多,刚上手时不知道怎么选择,所以贴在此处便后速查. 一次性读取 小文件推荐一次性读取,这样程序更简单,而且速度最快. 复制代码 代码如下: func ReadAll(fi ...
- Javascript写入txt和读取txt文件的方法
文章主要介绍了Javascript写入txt和读取txt文件的方法,需要的朋友可以参考下1. 写入 FileSystemObject可以将文件翻译成文件流. 第一步: 例: 复制代码 代码如下: Va ...
- 分享:Perl打开与读取文件的方法
在Perl中可以用open或者sysopen函数来打开文件进行操作,这两个函数都需要通过一个文件句柄(即文件指针)来对文件进行读写定位等操作. Perl打开与读取文件的方法,供大家学习参考.本文转自: ...
- PCB 无需解压,直接读取Genesis TGZ指定文件 实现方法
通过无需解压读取ZIP压缩包的方法,寻思者如何可以不解压直接读Genesis TGZ文件内容, 通过查找资料,原来可以通过:SharpCompress.dll工具实现此需求,此工具如此NB 一.Sha ...
随机推荐
- SDL播放声音
extern "C" { #include <libavcodec/avcodec.h> #include <libavformat/avformat.h> ...
- PHP 知识点链接
PHP 1.PHP中的危险函数全解析 http://www.php100.com/html/webkaifa/PHP/PHPyingyong/2009/0216/333 ...
- 【GoLang】GoLang 遍历 map、slice、array方法
代码示例: map1 := make(map[string]string) map1["a"] = "AAA" map1["b"] = &q ...
- CRC在线计算器
On-line CRC calculation and free library https://www.lammertbies.nl/comm/info/crc-calculation.html
- 饿了么 openapi demo
http://merchant.openapi.eleme.io/merchant.html#id215 class Program { static void Main(string[] args) ...
- VMware Workstation 下进行 桥连接
大家都知道进行桥连接的时候,需要我们的宿主机与虚拟机同处于一个网络段, 使得mask与默认网关相同即可进行连接 ; 本地的IP .掩码 . 网关: 虚拟机的Ip 掩码,网关: // 当然这里的DNS ...
- rebot的使用
rebot简要使用方法介绍 在介绍rebot前,首先说一下RobotFramework(后称RF)的主要输出文件. 当我们执行完一个RF脚本后,RF会输出3种文件.分别是Output.Log和Re ...
- centos7最小版本安装nginx+tomcat+java+mysql运行环境
最近项目从windows搬到linux,由于项目组成员有限并且有其它紧急的任务需要处理,因而这个任务就落到我的头上了.下面记录下centos最小版本安装nginx+tomcat+mysql+java的 ...
- C++中string,wstring,CString的基本概念和用法
一.概念 string和CString均是字符串模板类,string为标准模板类(STL)定义的字符串类,已经纳入C++标准之中.wstring是操作宽字符串的类.C++标准程序库对于string的设 ...
- MPlayer-2016-bin-noConsole
运行 Install-RMenu.cmd 添加右键播放功能 ; 往前0.05秒 大概10多个帧 ' 往后0.05秒 大概10多个帧 鼠标右键 快速定位 鼠标中键 退出 F1 缩小 F2 原始大小 F3 ...