首页 > Windows开发 > 详细

C#文件打开、读取、写入、创建

时间:2019-06-19 14:40:26      阅读:160      评论:0      收藏:0      [点我收藏+]

打开文件

打开文件夹,供操作者选择文件:

OpenFileDialog dialog = new OpenFileDialog();
dialog.ShowDialog();

获得所选文件的文件名:

string fileName=dialoa.FileName;

获取所选文件的文件夹目录:

FileInfo fi = new FileInfo(t);

string path = fileName.Substring(0, t.Length - fi.Name.Length);

将文件移动到别的目录:

string movePath="......";

fi.move(movePath);

/******************************************************

FileInfo类操作文件还有许多的情况不一一列举

******************************************************/

读取文件

StreamReader sr = new StreamReader(filePath);

sr.ReadLine();

 

往文件中写值

FileStream fStream = new FileStream(FilePath, FileMode.OpenOrCreate, FileAccess.Write);
StreamWriter sw = new StreamWriter(fStream);

sw.WriteLine();

sw.Close();

创建文件

string path="......."

 FileStream fStream = new FileStream(path, FileMode.OpenOrCreate, FileAccess.Write);

 

C#文件打开、读取、写入、创建

原文:https://www.cnblogs.com/YichengLiu/p/11050741.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!