本文整理汇总了C#中System.IO.FileInfo.OpenWrite方法的典型用法代码示例。如果您正苦于以下问题:C# FileInfo.OpenWrite方法的具体用法?C# FileInfo.OpenWrite怎么用?C# FileInfo.OpenWrite使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.IO.FileInfo
的用法示例。
在下文中一共展示了FileInfo.OpenWrite方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
//引入命名空间
using System;
using System.IO;
using System.Text;
class Test
{
public static void Main()
{
string path = @"c:\Temp\MyTest.txt";
FileInfo fi = new FileInfo(path);
// Open the stream for writing.
using (FileStream fs = fi.OpenWrite())
{
Byte[] info =
new UTF8Encoding(true).GetBytes("This is to test the OpenWrite method.");
// Add some information to the file.
fs.Write(info, 0, info.Length);
}
// Open the stream and read it back.
using (FileStream fs = fi.OpenRead())
{
byte[] b = new byte[1024];
UTF8Encoding temp = new UTF8Encoding(true);
while (fs.Read(b,0,b.Length) > 0)
{
Console.WriteLine(temp.GetString(b));
}
}
}
}
//This code produces output similar to the following;
//results may vary based on the computer/file structure/etc.:
//
//This is to test the OpenWrite method.
//
//
//
//
//
//
//
//
//
//
//
示例2: FileInfo.OpenWrite()
//引入命名空间
using System;
using System.IO;
public class MainClass
{
static void Main(string[] args)
{
FileInfo MyFiles = new FileInfo(@"c:\Testing.txt");
FileStream MyFileStream1 = MyFiles.OpenWrite();
byte MyWriteByte = 100;
MyFileStream1.WriteByte(MyWriteByte);
MyFileStream1.Close();
}
}