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 ...
随机推荐
- [20160725]ArithmeticTest
public class ArithmeticTest{ public static void main(String[] args) { int [] a={1,3,5,7,9,11,13,15}; ...
- Hadoop2.2.0环境下Sqoop1.99.3安装
本文转载自http://blog.csdn.net/liuwenbo0920/article/details/40504045 1.安装准备工作: 已经装好的hadoop环境是hadoop 2.2.0 ...
- REACT 学习
1.React/React Native 的ES5 ES6写法对照表 http://bbs.reactnative.cn/topic/15/react-react-native-%E7%9A%84es ...
- 【leetcode】N-Queens II
N-Queens II Follow up for N-Queens problem. Now, instead outputting board configurations, return the ...
- struts2 初步总结
1.Struts2的概述: 2.Struts2的入门: * 2.1下载struts2的zip包. * 2.2创建web工程. * 2.3配置... 3.Struts2的开发流程: * 3.1流程: * ...
- bbs/贴吧/盖楼的技术实现(PHP)
2015年3月5日 14:36:44 更新: 2015年7月18日 16:33:23 星期六 目标, 实现类似网易盖楼的功能, 但是不重复显示帖子 效果: * 回复 //1楼 ** 回复 //1楼的子 ...
- vs2013 控制台程序exe图标
工程右击选择添加resource->Icon. 在工程目录就会生成 工程名.rc 和 XX.ico文件. 重新编译程序,就会生成有图标的exe. 对应的配置在 工程名.rc 文件里,用记事 ...
- progressBar走马灯设置
初始值Visible = false; 让progressBar1出现时: progressBar1.Visible = true; progressBar1.Style = ProgressBarS ...
- JAVA volatile 关键字
一.volatile(易变的) Java 语言提供了一种稍弱的同步机制,即volatile修饰变量.用来确保将变量的更新操作通知到其他线程,保证了新值能立即同步到主内存,以及每次使用前立即从主内存刷新 ...
- [转]Android中Application类的用法
原文链接:http://www.cnblogs.com/renqingping/archive/2012/10/24/Application.html Application类 Application ...