本文整理汇总了C#中FileStream.WriteByte方法的典型用法代码示例。如果您正苦于以下问题:C# FileStream.WriteByte方法的具体用法?C# FileStream.WriteByte怎么用?C# FileStream.WriteByte使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FileStream
的用法示例。
在下文中一共展示了FileStream.WriteByte方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
static void Main( )
{
Stream s = new FileStream ( "foo.txt" , FileMode.Create ) ;
s.WriteByte ( 67 ) ;
s.WriteByte ( 35 ) ;
s.Close ( ) ;
}
示例2: BasicFlushFunctionality
public void BasicFlushFunctionality(bool? flushToDisk)
{
using (FileStream fs = new FileStream(GetTestFilePath(), FileMode.Create))
{
fs.WriteByte(0);
Flush(fs, flushToDisk);
fs.WriteByte(0xFF);
Flush(fs, flushToDisk);
}
}
示例3: BasicFlushAsyncFunctionality
public async Task BasicFlushAsyncFunctionality()
{
using (FileStream fs = new FileStream(GetTestFilePath(), FileMode.Create))
{
fs.WriteByte(0);
await fs.FlushAsync();
fs.WriteByte(0xFF);
await fs.FlushAsync();
}
}
示例4: Main
public static void Main(string[] args)
{
if (args.Length < 3 || !File.Exists(args[0]))
{
Console.WriteLine("pad file_in file_out pad");
return;
}
byte[] file_in = File.ReadAllBytes(args[0]);
FileStream file_out = new FileStream(args[1], FileMode.Create);
byte[] pad = new byte[args[2].Length*sizeof(char)];
System.Buffer.BlockCopy(args[2].ToCharArray(), 0, pad, 0, pad.Length);
// cheap hack deals with c# unicode default
for (int i = 0; i < pad.Length; i++) if (i%2==0) pad[i+1] = pad[i];
byte b_read = 0;
int p = 0;
for (long i = 0; i < file_in.Length; i++)
{
b_read = (byte) (file_in[i] ^ pad[p++]);
if (p >= pad.Length) p = 0;
file_out.WriteByte(b_read);
}
file_out.Close();
}
示例5: ReadOnlyThrows
public void ReadOnlyThrows()
{
string fileName = GetTestFilePath();
using (FileStream fs = new FileStream(fileName, FileMode.Create))
{
fs.Write(TestBuffer, 0, TestBuffer.Length);
}
using (FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read))
{
Assert.Throws<NotSupportedException>(() => fs.WriteByte(0));
fs.Dispose();
// Disposed checking happens first
Assert.Throws<ObjectDisposedException>(() => fs.WriteByte(0));
}
}
示例6: ReadDisposedThrows
public void ReadDisposedThrows()
{
using (FileStream fs = new FileStream(GetTestFilePath(), FileMode.Create))
{
fs.Dispose();
Assert.Throws<ObjectDisposedException>(() => fs.WriteByte(0));
}
}
示例7: StartWriting
void StartWriting (string name)
{
fileStream = new FileStream(name, FileMode.Create);
byte emptybyte = new byte();
for(int i = 0; i<headerSize; i++) //preparing the header
{
fileStream.WriteByte(emptybyte);
}
}
示例8: CreateEmpty
static FileStream CreateEmpty(string filepath) {
var fileStream = new FileStream(filepath, FileMode.Create);
byte emptyByte = new byte();
for(int i = 0; i < HEADER_SIZE; i++) //preparing the header
{
fileStream.WriteByte(emptyByte);
}
return fileStream;
}
示例9: FlushAsyncWhenNothingToFlush
public async Task FlushAsyncWhenNothingToFlush()
{
using (FileStream fs = new FileStream(GetTestFilePath(), FileMode.Create))
{
fs.WriteByte(0);
await fs.FlushAsync();
await fs.FlushAsync();
await fs.FlushAsync();
await fs.FlushAsync();
}
}
示例10: FlushWhenNothingToFlush
public void FlushWhenNothingToFlush(bool? flushToDisk)
{
using (FileStream fs = new FileStream(GetTestFilePath(), FileMode.Create))
{
fs.WriteByte(0);
Flush(fs, flushToDisk);
Flush(fs, flushToDisk);
Flush(fs, flushToDisk);
Flush(fs, flushToDisk);
}
}
示例11: Main
public static void Main(string[] args)
{
byte [] bytes = {70,71,72,73,74,75,13,10};
FileStream strm = new FileStream(@"..\..\WriteBinary.txt", FileMode.OpenOrCreate, FileAccess.Write);
foreach (byte bNext in bytes)
{
Console.WriteLine(bNext);
strm.WriteByte(bNext);
}
strm.Close();
Console.WriteLine("All done.");
Console.ReadLine();
}
示例12: Main
static void Main()
{
using (var file = new FileStream("../../../view.jpg", FileMode.Open))
{
using (var copyFile = new FileStream("../../CopyView.jpg", FileMode.Create))
{
while (file.Position < file.Length)
{
copyFile.WriteByte((byte)file.ReadByte());
}
}
}
}
示例13: Main
static int Main (string [] args)
{
using (FileStream fs = new FileStream ("tmp.txt", FileMode.Create, FileAccess.Write, FileShare.Read)) {
fs.WriteByte (5);
fs.Close ();
}
FileStream fs2 = new FileStream ("tmp.txt", FileMode.Open, FileAccess.Read, FileShare.Read);
try {
File.Delete ("tmp.txt");
return 1;
} catch (IOException) {
fs2.Close ();
File.Delete ("tmp.txt");
return 0;
}
}
示例14: WriteFile
public void WriteFile()
{
string fileName = GetTestFilePath();
using (FileStream fs = new FileStream(fileName, FileMode.Create))
{
foreach(byte b in TestBuffer)
{
fs.WriteByte(b);
}
}
using (FileStream fs = new FileStream(fileName, FileMode.Open))
{
byte[] buffer = new byte[TestBuffer.Length];
Assert.Equal(TestBuffer.Length, fs.Read(buffer, 0, buffer.Length));
Assert.Equal(TestBuffer, buffer);
}
}
示例15: WriteFile_PastBufferSize
public void WriteFile_PastBufferSize()
{
string fileName = GetTestFilePath();
using (FileStream fs = new FileStream(fileName, FileMode.Create))
{
for (int written = 0; written < TestBuffer.Length * 1000; written++)
{
fs.WriteByte(TestBuffer[written % TestBuffer.Length]);
}
}
byte[] buffer = File.ReadAllBytes(fileName);
int offset = 0;
while (offset < buffer.Length)
{
for (int i = 0; i < TestBuffer.Length; i++)
Assert.Equal(TestBuffer[i], buffer[i + offset]);
offset += TestBuffer.Length;
}
}