473,386 Members | 1,720 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Using FileStream or not?

Which is better to use, FileStream or File.Create?
Aug 28 '06 #1
3 2465
mo******@yahoo.com wrote:
Which is better to use, FileStream or File.Create?
File.Create uses FileStream. File acts as a neat starting point for lots
of file routines, so it can make code easier to read. In particular, if
you use File.Create you don't have to specify the right file mode etc.

If the use case you need is handled by one of the File methods like
File.Open / File.Create / File.CreateText etc., I'd advise using it,
because it ends up being more readable.

-- Barry

--
http://barrkel.blogspot.com/
Aug 28 '06 #2
The second still returns a FileStream. Just a static helper method for a
FileStream constructor. Myself, I using the FileStream, so the FileMode,
FileAccess and FileShare are explicitly documented in my code at a glance.

File.Create is a static helper:
public static FileStream Create(string path, int bufferSize, FileOptions
options)
{
return new FileStream(path, FileMode.Create, FileAccess.ReadWrite,
FileShare.None, bufferSize, options);
}

--
William Stacey [MVP]

<mo******@yahoo.comwrote in message
news:44***********************@fe4.nntpserver.com. ..
| Which is better to use, FileStream or File.Create?
Aug 28 '06 #3
mo******@yahoo.com wrote:
Which is better to use, FileStream or File.Create?
No functional difference.

I like the constructor because of its OO style.

The other is bit VBS'ish.

But that is just my personal taste.

Arne
Aug 28 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Shawn | last post by:
Hi. I'm using a FileStream (instead of just the path to the xml file) to load an XmlDocument. I'm doing this because I need to be able to prevent other processes to update the file I'm working on....
0
by: antsays | last post by:
I am trying to serialize a collection to disk using the code provided. This works just fine but when I try do copy and past the xml file to another location or sometimes even just click on the...
11
by: Dorsa | last post by:
HI, Could you please tell me the error in here. I am trying to open an XML file from a link. Response.Clear() Response.Expires = 0 Response.BufferOutput = False Response.ContentType =...
3
by: Terry | last post by:
In the code below, I open a file using filestream, copy it to a byte array, and the write that array out to a new file. But when I check the size of the original file and the new file, the new...
3
by: Loane Sharp | last post by:
Hi there I use the FileStream object to download a zip file over the internet to my local disk. The file downloads successfully, but when I attempt to unzip it, I'm told that the file is in use...
1
by: AMP | last post by:
Hello, I am trying to see if a FileStream Opened using an"if" clause: FileStream infile = new FileStream("c:\\blink2.txt", FileMode.Open, FileAccess.Read, FileShare.Read); if (infile==0)..... ...
8
by: Microsoft News | last post by:
Greetings community at large. I have a c# app that generates a PDF file. I have a printer that prints PDF natively. But I cannot figure out how to programatically print in C# ... I can...
3
by: JDeats | last post by:
I have some .NET 1.1 code that utilizes this technique for encrypting and decrypting a file. http://support.microsoft.com/kb/307010 In .NET 2.0 this approach is not fully supported (a .NET 2.0...
13
by: =?Utf-8?B?Um9nZXIgTWFydGlu?= | last post by:
This is a follow-up to my post "Silverlight video doesn't work when file is streamed from handler in ASP.net" at...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.