如何使用StreamWriter创建目录? [英] How to create a directory using StreamWriter?

查看:41
本文介绍了如何使用StreamWriter创建目录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Is it possible to create a directory using StreamWriter?

推荐答案

否.您实际上无法使用StreamWriter创建目录.改用 Directory.CreateDirectory .

No. You can't actually create a directory using a StreamWriter. Use Directory.CreateDirectory instead.

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

If you're trying to read the directory name out of a file stream and then create a file based on that text, you'll need something like this:

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

这篇关于如何使用StreamWriter创建目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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