theKing
theKing

Reputation: 1636

How to create a directory using StreamWriter?

Is it possible to create a directory using StreamWriter?

Upvotes: 20

Views: 17436

Answers (1)

Chris Hynes
Chris Hynes

Reputation: 10239

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());

Upvotes: 25

Related Questions