FileInfoOpen(FileMode) Method |
Opens a file in the specified mode.
Namespace: Crestron.SimplSharp.CrestronIOAssembly: SimplSharpHelperInterface (in SimplSharpHelperInterface.dll) Version: 2.21.121
Syntaxpublic FileStream Open(
FileMode mode
)
Parameters
- mode FileMode
- Specified mode to open the file. (Open, Append, etc.)
Return Value
FileStreamA file opened in the specified mode, with read/write access and unshared.
Exceptions
Example
using Crestron.SimplSharp;
using Crestron.SimplSharp.CrestronIO;;
class Test
{
public static void Main()
{
string path = @"\User\MyTest.txt";
FileInfo fi = new FileInfo(path);
// Delete the file if it exists.
if (!fi.Exists)
{
//Create the file.
using (FileStream fs = fi.Create())
{
Byte[] info = new UTF8Encoding(true).GetBytes("This is some text in the file.");
//Add some information to the file.
fs.Write(info, 0, info.Length);
}
}
//Open the stream and read it back.
using (FileStream fs = fi.Open(FileMode.Open))
{
byte[] b = new byte[1024];
UTF8Encoding temp = new UTF8Encoding(true);
while (fs.Read(b, 0, b.Length) > 0)
{
......
}
}
}
}
Version Information
.NET
Supported in: 6.0
.NET Compact Framework
Supported in: 3.5
See Also