如何将字符串解析为StreamWriter对象 [英] How to Parse a string to a StreamWriter object

查看:70
本文介绍了如何将字符串解析为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!

推荐答案

0)为什么您同时打开了这么多文件?那是极其低效的.

1)您发布的第一行代码应如下所示:

0) WHY do you have so many files open at the same time? That''s extremely inefficient.

1) The first line of code you posted should look like this:

StreamWriter handle = new StreamWriter("C:\\myfile001.txt");


这篇关于如何将字符串解析为StreamWriter对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆