【学习笔记】C#文件流联系|读取文件、追加Txt
来源:互联网 发布:ubuntu设置root密码 编辑:程序博客网 时间:2024/05/19 02:04
//读取文件 方式1
string filePath = HttpRuntime.AppDomainAppPath + "/Resource/File/filetest.txt";
FileStream file = new FileStream(filePath, FileMode.Open);
StreamReader sr = new StreamReader(file);
string result = sr.ReadToEnd();
sr.Close();
/*=========================================*/
//读取文件 方式2
StreamReader sr2 = new StreamReader(filePath, Encoding.UTF8);
string result2 = sr2.ReadToEnd();
sr2.Close();
/*=========================================*/
//遍历文件每一行
StreamReader sr3 = new StreamReader(filePath, Encoding.Default);
string str = sr3.ReadLine();
while (str != null)
{
//处理str
str = sr3.ReadLine();
}
sr3.Close();
/*=========================================*/
//追加内容到txt
StreamWriter sw = new StreamWriter(filePath, true, Encoding.Default);
sw.WriteLine("追加内容");
sw.Close();
/*=========================================*/
//判断文件是否存在
if (System.IO.File.Exists(filePath))
{
string isexist = "";
}
//判断目录是否存在
string filePath3 = HttpRuntime.AppDomainAppPath + "/Resource/File";
if (Directory.Exists(filePath3))
{
string isexist = "";
}
string filePath = HttpRuntime.AppDomainAppPath + "/Resource/File/filetest.txt";
FileStream file = new FileStream(filePath, FileMode.Open);
StreamReader sr = new StreamReader(file);
string result = sr.ReadToEnd();
sr.Close();
/*=========================================*/
//读取文件 方式2
StreamReader sr2 = new StreamReader(filePath, Encoding.UTF8);
string result2 = sr2.ReadToEnd();
sr2.Close();
/*=========================================*/
//遍历文件每一行
StreamReader sr3 = new StreamReader(filePath, Encoding.Default);
string str = sr3.ReadLine();
while (str != null)
{
//处理str
str = sr3.ReadLine();
}
sr3.Close();
/*=========================================*/
//追加内容到txt
StreamWriter sw = new StreamWriter(filePath, true, Encoding.Default);
sw.WriteLine("追加内容");
sw.Close();
/*=========================================*/
//判断文件是否存在
if (System.IO.File.Exists(filePath))
{
string isexist = "";
}
//判断目录是否存在
string filePath3 = HttpRuntime.AppDomainAppPath + "/Resource/File";
if (Directory.Exists(filePath3))
{
string isexist = "";
}
阅读全文
0 0
- 【学习笔记】C#文件流联系|读取文件、追加Txt
- c#读取txt文件
- C#读取TXT文件
- C#读取TXT文件
- C#读取TXT文件
- C#读取txt文件
- C# 读取txt文件
- c# txt文件末尾追加字符方法
- 黑马程序员之C#学习笔记:C#读取txt文件的方法
- C#如何读取.TXT文件
- C# 读取TXT文件程序
- c# 读取txt文件内容
- C# 读取Txt文件内容
- c# 倒序读取txt文件
- TXT文件学习笔记
- C#为txt文件追加文字并换行
- 读取文件并追加
- c#读取简单的TXT文件
- bootstrap.jar which is referenced by the classpath, does not exist.
- 自定义函数 function
- hashCode的作用及与equals的关系
- centos7.2 利用crontab执行定时计划任务
- 洛谷3941 入阵曲
- 【学习笔记】C#文件流联系|读取文件、追加Txt
- UE4 蓝图类对象如果需要接受Input输入时?
- IDA-数据显示窗口(反汇编窗口、函数窗口、十六进制窗口)
- 编写一个函数完成n^k计算
- nodeJs windows安装
- 自己写的简单csv文件下载
- centos7 nagios 配置被动模式监控
- 安卓动态调试七种武器之孔雀翎 – Ida Pro
- 如何控制应用程序使用的內存?