如何使用StreamWriter创建目录?

是否可以使用StreamWriter创建目录?

不可以。您无法使用StreamWriter实际创建目录。 请改用Directory.CreateDirectory 。

如果您尝试从文件流中读取目录名称,然后根据该文本创建文件,则需要以下内容:

FileStream fs; // this is the filestream from somewhere. make sure to dispose it using (StreamReader r = new StreamReader(fs)) Directory.CreateDirectory(r.ReadToEnd());