首页 技术 正文
技术 2022年11月14日
0 收藏 960 点赞 4,529 浏览 1666 个字
class Program
{
static void Main(string[] args)
{
EmployeeDAL DAL = new EmployeeDAL();
List<Sys_Employee> list = DAL.GetAll().ToList();
//WriteTxt(list);
//DeleDirFile();
Console.WriteLine("请输入文件路径!");
string path = Console.ReadLine();
ReadTxt(path);
} #region 对文件的操作 //写文件
public static void WriteTxt(List<Sys_Employee> Emp)
{
string path = @"F:\CreateDirTxt"; if (!Directory.Exists(path))
{
Directory.CreateDirectory(path);
}
foreach (var emp in Emp)
{
//创建文件流
FileStream Stream = new FileStream(@"F:\CreateDirTxt\" + emp.EmpName + "信息文本.txt", FileMode.Create);
StreamWriter Writer = new StreamWriter(Stream);
//向流中写入内容
Writer.Write(string.Format("姓名是:{0},性别是:{1},地址是:{2}", EmpName, emp.EmpSex, emp.EmpAddress));
//清空缓存
Writer.Flush();
//关闭
Writer.Close();
Console.WriteLine("正在创建 " + emp.EmpName + " 的信息文本");
}
Console.WriteLine("创建完成 O(∩_∩)O");
Console.ReadLine();
}
//删文件
public static void DeleDirFile()
{
string path = @"F:\CreateDirTxt\";
if (Directory.Exists(path))
{
//获得文件夹数组
string[] Directorlenght = Directory.GetDirectories(path);
//获得文件数组
string[] filelength = Directory.GetFiles(path);
//遍历删除文件夹
foreach (string lst in Directorlenght)
{
Directory.Delete(lst);
}
//遍历删除文件
foreach (string lst in filelength)
{
int Index = lst.LastIndexOf("\\") + ;
string EmpName = lst.Substring(Index, lst.Length - Index);
File.Delete(lst);
Console.WriteLine("文件 -"+EmpName+"- 删除成功");
}
Console.WriteLine("完成! O(∩_∩)O");
}
else
{
Console.WriteLine("文件或者文件夹不存在,请重新查看");
}
Console.ReadLine();
}
//读文件 -按照每行进行读取
public static void ReadTxt(string FilePath)
{
string path = @FilePath;    //路径
if (File.Exists(@FilePath))   /判断路径是否存在
{
StreamReader Reader = new StreamReader(path,Encoding.UTF8);
string linetext;
while ((linetext=Reader.ReadLine())!=null)
{
Console.WriteLine(linetext);
}
}
else
{
Console.WriteLine("该文件不存在!");
}
Console.ReadLine();
} #endregion
上一篇: SQLite中的FROM子句
下一篇: element对象
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,491
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,907
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,740
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,493
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:8,132
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:5,294