首页 > 技术文章 > 关于写文件流的情况

loushuibazi 2014-09-25 11:19 原文

最初写信息到ini文件中

File.Create(uIniPath);

StreamWriter sw = new StreamWriter(uIniPath);

sw.WriteLine("");

sw.Flush();

sw.Close();

 

以上代码,偶尔会出现进程被使用,无法调用的问题,于是用下面这种

using(FileStream fs = File.Create(uIniPath))

{

  byte[] info = new UTF8Encoding(true).GetBytes("");

  fs.Write(info,0,info.Length);

}

 

这样写避免了进程访问的问题,但是似乎内容换行不方便,于是又找了下面这种写法

using(FileStream fs = File.Create(uIniPath))

{

  StreamWriter sw = new StreamWriter(fs);

  sw.WriteLine("");

  sw.Close();

}

 

至此,满足现有要求。

如有啥问题,欢迎交流

 

推荐阅读