本文整理汇总了C#中System.IO.BinaryWriter.Close方法的典型用法代码示例。如果您正苦于以下问题:C# System.IO.BinaryWriter.Close方法的具体用法?C# System.IO.BinaryWriter.Close怎么用?C# System.IO.BinaryWriter.Close使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.IO.BinaryWriter
的用法示例。
在下文中一共展示了System.IO.BinaryWriter.Close方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: getPdfFile
public void getPdfFile(string fileName)
{
using (SqlConnection cn = new SqlConnection(ConnectionString))
{
cn.Open();
using (SqlCommand cmd = new SqlCommand($"select FileSource from PdfDocumentFiles where Name='{fileName}' ", cn))
{
using (SqlDataReader dr = cmd.ExecuteReader(System.Data.CommandBehavior.Default))
{
if (dr.Read())
{
byte[] fileData = (byte[])dr.GetValue(0);
using (System.IO.FileStream fs = new System.IO.FileStream(fileName, System.IO.FileMode.Create, System.IO.FileAccess.ReadWrite))
{
using (System.IO.BinaryWriter bw = new System.IO.BinaryWriter(fs))
{
bw.Write(fileData);
bw.Close();
}
}
}
dr.Close();
}
}
}
}
示例2: CreateSelfSignCertificate
static void CreateSelfSignCertificate(CertOption option)
{
var fileName = option.CertFileName;
var subject = option.Subject;
var password = option.Password;
try
{
var securePassword = Certificate.ConvertSecureString(password);
var startDate = DateTime.Now;
var endDate = startDate.AddYears(option.Years);
var certData = Certificate.CreateSelfSignCertificatePfx(subject, startDate, endDate, securePassword);
using (var writer = new System.IO.BinaryWriter(System.IO.File.Open(fileName, System.IO.FileMode.Create)))
{
writer.Write(certData);
writer.Flush();
writer.Close();
}
securePassword = Certificate.ConvertSecureString(password);
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
}
示例3: PNGtoBIN
public static void PNGtoBIN(string path_in, string path_out, string[] param = null)
{
Image png = Image.FromFile(path_in);
Bitmap bmp = new Bitmap(png);
if ((png.Width != 128) && (png.Height != 32))
return;
int tiles_w = png.Width / 4;
int tiles_h = png.Height / 8;
ushort[] binary = new ushort[256];
for (int y = 0; y < tiles_h; y++)
{
for (int x = 0; x < tiles_w; x++)
{
ushort[] tile = new ushort[2];
for (int iY = 0; iY < 8; iY++)
{
for (int iX = 0; iX < 4; iX++)
{
Color color = bmp.GetPixel(x * 4 + iX, y * 8 + iY);
if (color.R + color.G + color.B > 0x0100)
tile[(iY / 4)] |= (ushort)(1 << ((iY % 4) * 4 + iX));
}
}
binary[y * tiles_w * 2 + x * 2 + 0] = tile[0];
binary[y * tiles_w * 2 + x * 2 + 1] = tile[1];
}
}
System.IO.BinaryWriter writer = new System.IO.BinaryWriter(System.IO.File.Open(path_out, System.IO.FileMode.Create));
for (int i = 0; i < 256; i++)
writer.Write(binary[i]);
writer.Close();
}
示例4: SerializeVoxelAreaCompactData
public static byte[] SerializeVoxelAreaCompactData (VoxelArea v) {
System.IO.MemoryStream stream = new System.IO.MemoryStream();
System.IO.BinaryWriter writer = new System.IO.BinaryWriter(stream);
writer.Write (v.width);
writer.Write (v.depth);
writer.Write (v.compactCells.Length);
writer.Write(v.compactSpans.Length);
writer.Write(v.areaTypes.Length);
for (int i=0;i<v.compactCells.Length;i++) {
writer.Write(v.compactCells[i].index);
writer.Write(v.compactCells[i].count);
}
for (int i=0;i<v.compactSpans.Length;i++) {
writer.Write(v.compactSpans[i].con);
writer.Write(v.compactSpans[i].h);
writer.Write(v.compactSpans[i].reg);
writer.Write(v.compactSpans[i].y);
}
for (int i=0;i<v.areaTypes.Length;i++) {
//TODO: RLE encoding
writer.Write(v.areaTypes[i]);
}
writer.Close();
return stream.ToArray();
}
示例5: ByteArrayToFile
public bool ByteArrayToFile(string _FileName, byte[] _ByteArray)
{
try
{
// Open file for reading
System.IO.FileStream _FileStream =
new System.IO.FileStream(_FileName, System.IO.FileMode.Create,
System.IO.FileAccess.Write);
System.IO.BinaryWriter bw = new System.IO.BinaryWriter(_FileStream);
// Writes a block of bytes to this stream using data from
// a byte array.
bw.Write(_ByteArray, 0, _ByteArray.Length);
// close file stream
bw.Close();
return true;
}
catch (Exception _Exception)
{
// Error
Console.WriteLine("Exception caught in process: {0}",
_Exception.ToString());
}
// error occured, return false
return false;
}
示例6: SerializeVoxelAreaCompactData
public static byte[] SerializeVoxelAreaCompactData (VoxelArea v) {
#if !ASTAR_RECAST_CLASS_BASED_LINKED_LIST
System.IO.MemoryStream stream = new System.IO.MemoryStream();
System.IO.BinaryWriter writer = new System.IO.BinaryWriter(stream);
writer.Write (v.width);
writer.Write (v.depth);
writer.Write (v.compactCells.Length);
writer.Write(v.compactSpans.Length);
writer.Write(v.areaTypes.Length);
for (int i=0;i<v.compactCells.Length;i++) {
writer.Write(v.compactCells[i].index);
writer.Write(v.compactCells[i].count);
}
for (int i=0;i<v.compactSpans.Length;i++) {
writer.Write(v.compactSpans[i].con);
writer.Write(v.compactSpans[i].h);
writer.Write(v.compactSpans[i].reg);
writer.Write(v.compactSpans[i].y);
}
for (int i=0;i<v.areaTypes.Length;i++) {
//TODO: RLE encoding
writer.Write(v.areaTypes[i]);
}
writer.Close();
return stream.ToArray();
#else
throw new System.NotImplementedException ("This method only works with !ASTAR_RECAST_CLASS_BASED_LINKED_LIST");
#endif
}
示例7: Assemble
public static void Assemble(string infile, string outfile, string origin)
{
CurrentNdx = 0;
AsLength = Convert.ToUInt16(origin, 16);
IsEnd = false;
ExecutionAddress = 0;
LabelTable = new System.Collections.Hashtable(50);
System.IO.BinaryWriter output;
System.IO.TextReader input;
System.IO.FileStream fs = new System.IO.FileStream(outfile, System.IO.FileMode.Create);
output = new System.IO.BinaryWriter(fs);
input = System.IO.File.OpenText(infile);
SourceProgram = input.ReadToEnd();
input.Close();
output.Write('B');
output.Write('3');
output.Write('2');
output.Write(Convert.ToUInt16(origin, 16));
output.Write((ushort)0);
Parse(output, origin);
output.Seek(5, System.IO.SeekOrigin.Begin);
output.Write(ExecutionAddress);
output.Close();
fs.Close();
}
示例8: Save
public static void Save(string directory, string file,string ext, XCImageCollection images)
{
System.IO.BinaryWriter bw = new System.IO.BinaryWriter(System.IO.File.Create(directory+"\\"+file+ext));
foreach(XCImage tile in images)
bw.Write(tile.Bytes);
bw.Flush();
bw.Close();
}
示例9: calcbodysize
public override void calcbodysize()
{
System.IO.BinaryWriter bw = new System.IO.BinaryWriter(new System.IO.MemoryStream());
ToStream(bw);
size = Convert.ToInt32(bw.BaseStream.Length);
bw.Close();
bw.Dispose();
}
示例10: WriteZippedResources
public void WriteZippedResources()
{
using (var binWriter = new System.IO.BinaryWriter(this.fileSystem.File.OpenWrite(MyDhtmlResourceSet.ZippedResources.LocalPath)))
{
binWriter.Write(Properties.Resources.Pickles_BaseDhtmlFiles);
binWriter.Flush();
binWriter.Close();
}
}
示例11: DecodingFileFromString
/// <summary>
/// 将Base64编码字符串解码并存储到一个文件中
/// </summary>
/// <param name="Base64String">经过Base64编码后的字符串</param>
/// <param name="strSaveFileName">要输出的文件路径,如果文件存在,将被重写</param>
/// <returns>如果操作成功,则返回True</returns>
public static bool DecodingFileFromString(string Base64String, string strSaveFileName)
{
System.IO.FileStream fs = new System.IO.FileStream(strSaveFileName, System.IO.FileMode.Create);
System.IO.BinaryWriter bw = new System.IO.BinaryWriter(fs);
bw.Write(Convert.FromBase64String(Base64String));
//bw.Write(Convert.ToBase64String)
bw.Close();
fs.Close();
return true;
}
示例12: Main
static void Main(string[] args)
{
var options = new SwitchOptions();
if (!CommandLine.ParseArguments(args, options))
return;
try
{
if (String.IsNullOrEmpty(options.outFile))
{
Console.WriteLine("You must supply an outfile.");
return;
}
var source = new System.IO.StreamReader(options.inFile);
var lexed = new LexResult();
var r = Lexer.Lex(source, lexed);
if (r == 0x00)
{
var destination = System.IO.File.Open(options.outFile, System.IO.FileMode.Create);
var writer = new System.IO.BinaryWriter(destination);
r = Assembler.Assemble(lexed, writer);
writer.Flush();
destination.Flush();
writer.Close();
}
Console.WriteLine("Finished with code " + r);
}
/*case "emulate":
{
var source = System.IO.File.Open(options.inFile, System.IO.FileMode.Open);
var emulator = new IN8();
source.Read(emulator.MEM, 0, 0xFFFF);
// Attach devices
var teletypeTerminal = new TT3();
emulator.AttachHardware(teletypeTerminal, 0x04);
while (emulator.STATE_FLAGS == 0x00) emulator.Step();
Console.WriteLine(String.Format("Finished in state {0:X2}", emulator.STATE_FLAGS));
Console.WriteLine(String.Format("{0:X2} {1:X2} {2:X2} {3:X2} {4:X2} {5:X2} {6:X2} {7:X2}",
emulator.A, emulator.B, emulator.C, emulator.D, emulator.E, emulator.H, emulator.L, emulator.O));
Console.WriteLine(String.Format("{0:X4} {1:X4} {2:X8}", emulator.IP, emulator.SP, emulator.CLOCK));
break;
}
}
}*/
catch (Exception e)
{
Console.WriteLine("An error occured.");
Console.WriteLine(e.Message);
Console.WriteLine(e.StackTrace);
}
}
示例13: StreamToFile
/// <summary>
/// 将 Stream 写入文件
/// </summary>
/// <param name="stream"></param>
/// <param name="fileName"></param>
public static void StreamToFile(this System.IO.Stream stream, string fileName)
{
// 把 Stream 转换成 byte[]
var bytes = new byte[stream.Length];
stream.Read(bytes, 0, bytes.Length);
// 设置当前流的位置为流的开始
stream.Seek(0, System.IO.SeekOrigin.Begin);
// 把 byte[] 写入文件
var fs = new System.IO.FileStream(fileName, System.IO.FileMode.Create);
var bw = new System.IO.BinaryWriter(fs);
bw.Write(bytes);
bw.Close();
fs.Close();
}
示例14: btnExport_Click
private void btnExport_Click(object sender, EventArgs e)
{
System.IO.BinaryWriter bw = new System.IO.BinaryWriter(System.IO.File.Open("export.txt", System.IO.FileMode.Create));
bw.Write(width);//columns
bw.Write(height);//rows
for (int x = 0; x < width; x++)
{
for (int y = 0; y < height; y++)
{
bw.Write(mapData[x, y]);
}
}
bw.Close();
}
示例15: SaveData
/// <summary>
/// ファイルにデータをセーブ
/// </summary>
public static void SaveData()
{
using(var fs = System.IO.File.Open(@SAVEFILE,System.IO.FileMode.CreateNew)){
// バイナリライター作成
var bw = new System.IO.BinaryWriter(fs);
// Write data
bw.Write(Global.isStageOpened[(int)StageID.Stage1]);
bw.Write(Global.isStageOpened[(int)StageID.Stage2]);
bw.Write(Global.isStageOpened[(int)StageID.Stage3]);
bw.Write(Global.characterLevel);
bw.Write(Global.characterExp);
bw.Close();
}
}