Open


Open

Opens a file with a specified mode, access and share returning a FileStream object
The sharing mode lets you control whether or not other processes can read from or write to the file while you have it open.
A lot of the arguments correspond to overloads of the FileStream constructor.
This method gives you greater (than the Create, OpenRead and OpenWrite methods) when creating new files.
If you want total control when opening and creating files then you should use the FileStream constructor.

System.IO.File.Open(file [,mode [,access [,share ]]]) 
System.IO.File.Open("C:\temp\file1.txt", _
                    FileMode.Append | Create | CreateNew | Open | OpenOrCreate | Truncate, _
                    FileAccess.Read | Write | ReadWrite, _
                    FileShare.None | ReadWrite | Read | Write | Inheritable

OpenRead

Opens an existing file in read mode returning a FileStream object
The file is opened using the default sharing mode
The FileStream is positioned at the beginning of the file.

System.IO.File.OpenRead(file) 

System.IO.FileStream oFileStream; 
oFileStream = System.IO.File.OpenRead("C:\Temp\textfile.txt");

OpenWrite

Opens a file in write mode returning a FileStream object
Any existing data in the file will be overwritten.
If the file you are trying to open does not exist then it will be created.

System.IO.File.OpenWrite(file); 

OpenText

Opens a text file for reading returning a StreamReader object
This method returns a StreamReader that is positioned at the beginning of the file.

System.IO.File.OpenText(file); 


© 2024 Better Solutions Limited. All Rights Reserved. © 2024 Better Solutions Limited TopPrevNext