本文介绍了如何将字符串解析为StreamWriter对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我打开了大量文件句柄(约500个).
这些文件句柄的名称是文件路径,例如
C:\ myFile001.txt
现在,我希望向其中一个文件中写入一些数据:
我尝试
I have a large number of file handles open (c. 500).
the names of the these file handles are file paths eg
C:\myFile001.txt
I now wish to write some data to one of the files:
I try
StreamWriter handle = "C:\myFile001.txt";
handle.WriteLine(message.ToString());
但是,我得到了错误:
无法将类型字符串"隐式转换为"System.IO.StreamWriter"
我已经尝试了从字符串到StreamWriter的简单转换,但这也不起作用.
感谢您的帮助!
however, I get the error:
Cannot implicitly convert type ''string'' to ''System.IO.StreamWriter''
I have tried a simple cast from string to StreamWriter, but that doesnt work either.
Any help gratefully recieved!
推荐答案
StreamWriter handle = new StreamWriter("C:\\myfile001.txt");
这篇关于如何将字符串解析为StreamWriter对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!