C#文本文件操作
2013-10-08 20:50
190 查看
//文本文件创建、读写、删除
string path = @"F:\FILE.txt";
if (!File.Exists(path))
{
//创建、写
using (StreamWriter sw = File.CreateText(path))
{
sw.WriteLine("大琳仔");
}
}
//追加
using (StreamWriter sw = File.AppendText(path))
{
sw.WriteLine("小琳仔");
}
//读
string s;
using (StreamReader sr = File.OpenText(path))
{
while ((s = sr.ReadLine()) != null)
{
Console.WriteLine(s);
}
}
//拷贝
try
{
File.Copy(path,@"F:\F.txt");
}
catch (Exception e)
{
Console.WriteLine("拷贝失败:" + e.Message);
}
//删除
try
{
File.Delete(path);
}
catch(Exception e)
{
Console.WriteLine("删除失败:"+e.Message);
}
string path = @"F:\FILE.txt";
if (!File.Exists(path))
{
//创建、写
using (StreamWriter sw = File.CreateText(path))
{
sw.WriteLine("大琳仔");
}
}
//追加
using (StreamWriter sw = File.AppendText(path))
{
sw.WriteLine("小琳仔");
}
//读
string s;
using (StreamReader sr = File.OpenText(path))
{
while ((s = sr.ReadLine()) != null)
{
Console.WriteLine(s);
}
}
//拷贝
try
{
File.Copy(path,@"F:\F.txt");
}
catch (Exception e)
{
Console.WriteLine("拷贝失败:" + e.Message);
}
//删除
try
{
File.Delete(path);
}
catch(Exception e)
{
Console.WriteLine("删除失败:"+e.Message);
}
相关文章推荐
- C#文本文件操作
- c# 流的概念以及一个操作文本文件的实例代码
- C#文本文件的操作
- c# 中读写ini文件(C#操作文本文件、C#读写文本文件)
- c#中读写ini文件(C#操作文本文件、C#读写文本文件)
- C#操作文本文件
- C#创建创建文本文件写入读取,可以用来做系统日志或程序操作日志或者错误记录
- C#操作文本文件(入门)
- C#操作文本文件 在行首和行尾追加文本
- c#操作文本文件或日志文件封装类
- C# 常用文件操作 文本文件 二进制文件 读写操作
- C#操作文本文件(.txt)[转]
- C# 文本文件操作 IO流
- c#操作文本文件
- c#操作文本文件
- C# 文本文件操作 IO流
- 在c#中如何操作文本文件
- 文本文件操作(C#)
- c#操作文本文件
- C#操作文本文件