![](/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.