1

Is there any performance or any kind of effect on OS's file system permission between the codes below:

FileStream fs = new FileStream(@"file.dat", FileMode.Create, FileAccess.Write);
// and
FileStream fs = File.Create(@"file.dat");

PS: except the usage of a static function issue.

2 Answers 2

3

According to reflector, File.Create(path) is just:

new FileStream(path, FileMode.Create, FileAccess.ReadWrite, FileShare.None, 4096, FileOptions.None);

and new FileStream(@"file.dat", FileMode.Create, FileAccess.Write) also gets the 4096 buffer - so no, it is just the FileAccess.ReadWrite which is different.

And I don't think FileAccess.Write is much better than FileAccess.ReadWrite because they both locks the file - but I may be wrong.

to comment: because FileShare is set to None and it is write access you want they properly (=I don't know for sure) ain't much of a difference. However, if you wanted Read access the new FileStream(path, mode, access) approach is different because FileShare is set to Read as a default. However, in this case you want to create a file, and therefore it does not make much sense to only read ;-)

Sign up to request clarification or add additional context in comments.

2 Comments

Ok, I decompiled the code with reflector too before asking the question.. but I was wondering if there is any performance difference between FileAccess.Write and FileAccess.ReadWrite methods in OS side? (I just got a problem with Win7 file system that's why I'm asking...)
@Bora see update :-) Not really want your looked for, though.
2

If I recall correctly, File.Create("file.dat") just wraps a call to new FileStream("file.dat", FileMode.Create, FileAccess.ReadWrite).

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.