File Operations in C#
-
Thursday, April 12, 2012 6:32 AM
Can u please help me with the Following file access mode
if we open a file with the following modes what will be the output?
l "r": Reading access (if File not exists what this will do)
l "w": Write-in access (if File not exists what this will do)
l "a": Access write-in [ appending ] (if File not exists what this will do)
- Edited by Avatar 123 Thursday, April 12, 2012 6:33 AM
All Replies
-
Thursday, April 12, 2012 6:37 AM
Why don`t you try by yourself ?Hannes
If you have got questions about this, just ask.
In a perfect world,
users would never enter data in the wrong form,
files they choose to open would always exist
and code would never have bugs.
C# to VB.NET: http://www.developerfusion.com/tools/convert/csharp-to-vb/- Proposed As Answer by Cor LigthertMVP Thursday, April 12, 2012 7:06 AM
-
Thursday, April 12, 2012 6:48 AM
http://msdn.microsoft.com/en-us/library/4z36sx0f(VS.80).aspx
Kindly have a look at the above link.
Regards,
Narendran Ponpandiyan
-
Thursday, April 26, 2012 2:50 AMModerator
- "r": Reading access (if File not exists what this will do)
FileStream sRead= new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.Read);
Specifies that the operating system should open an existing file. The ability to open the file is dependent on the the value specified by FileAccess. A System.IO.FileNotFoundException is thrown if the file does not exist.
- l "w": Write-in access (if File not exists what this will do)
FileStream sWrite= new FileStream(filename, FileMode.Open, FileAccess.Write, FileShare.Write);
Specifies that the operating system should open an existing file. The ability to open the file is dependent on the the value specified by FileAccess. A System.IO.FileNotFoundException is thrown if the file does not exist.
l "a": Access write-in [ appending ] (if File not exists what this will do)
FileStream sAppend= new FileStream(filename, FileMode.Append, FileAccess.Write, FileShare.Write);
Opens the file if it exists and seeks to the end of the file, or creates a new file. FileMode.Append can only be used in conjunction with FileAccess.Write. Any attempt to read fails and throws an ArgumentException.
More information, please refer:
http://msdn.microsoft.com/en-au/library/system.io.filemode(v=vs.80).aspx
http://msdn.microsoft.com/en-us/library/4z36sx0f(v=VS.71).aspx
Mike Zhang[MSFT]
MSDN Community Support | Feedback to us
- Marked As Answer by Michael Sun [MSFT]Microsoft Employee, Moderator Thursday, April 26, 2012 3:02 AM

