![](/img/trans.png)
[英]How to fix StreamWriter error “cannot implicitly convert type string to System.IO.StreamWriter”
[英]Cannot implicitly convert type string to to StreamWriter
我正在尝试将文件分成10个部分。 这是我认为可以做到的方式,但出现标题中提到的错误。 有解决此问题的简便方法吗?
StreamWriter a = new StreamWriter(new FileStream(@"C:\work\missing" + num + ".txt");
using (var r = new StreamReader(readMissing))
{
var rr = r.ReadLine();
while (rr != null)
{
a.WriteLine(rr);
count++;
if (count == 36139)
{
iNum = Int32.Parse(num);
iNum++;
num = iNum.ToString();
a = (@"C:\work\missing" + num + ".txt"); //problem line
count = 0;
}
rr = r.ReadLine();
}
a.Close();
}
为了解决这个问题,你必须实例化一个新的对象StreamWriter
:
a.Close();
a = new StreamWriter(@"C:\work\missing" + num + ".txt");
但要记住先关闭它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.