本文整理匯總了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();
}
}