日本免费全黄少妇一区二区三区-高清无码一区二区三区四区-欧美中文字幕日韩在线观看-国产福利诱惑在线网站-国产中文字幕一区在线-亚洲欧美精品日韩一区-久久国产精品国产精品国产-国产精久久久久久一区二区三区-欧美亚洲国产精品久久久久

如何打開bin文件 dwg.bin格式文件用什么軟件打開


如何打開bin文件 dwg.bin格式文件用什么軟件打開


BIN文件 , 即二進(jìn)制文件,廣泛應(yīng)用于嵌入式 , 我們常用的Firmware通常會以BIN文件或者HEX文件格式存儲,因此,對BIN文件的讀寫操作其實還是很普遍的,在這里,我記錄一下我常用到的BIN文件操作 。
首先C# Winform中有Binary文件(BIN文件)的基本操作類 。如下所示
FileStream file_path = new FileStream(文件名, FileMode,FileAccess);//BinaryReader bin_read = new BinaryReader(file_path);BinaryWriter bin_write = new BinaryWriter(file_path);如上所示 , 如果是要讀BIN文件,那么直接定義BinaryReader即可,如果是要寫B(tài)IN文件,定義BInaryWriter 。讀寫的基本操作為:
讀BIN文件的操作為:bin_read.ReadByte():返回值為讀到的Byte值;bin_read.ReadBytes(count);返回值為個數(shù)為count的Byte數(shù)組 。還有很多不同返回格式,int,char等 , 我這里不一一贅述 。
寫B(tài)IN文件的操作為:bin_write.Write(value):其中value就是要寫的值,value可以是byte,int或者char等格式 。bin_write.Write(byte[] buffer, int index, int count);這個方法的含義就是將buffer數(shù)組中的一部分值(buffer數(shù)組的開始索引為index,長度為count),賦值至BIN文件當(dāng)前位置 。
下面我舉一個例子,BIN文件的寫 , 從0寫到255,256個byte 。
using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Windows.Forms;using System.IO;namespace TEST{public partial class Form1 : Form{public Form1(){InitializeComponent();}private void button1_Click(object sender, EventArgs e){SaveFileDialog save_file = new SaveFileDialog();save_file.Filter = "BIN文件|*.bin";if (save_file.ShowDialog() == DialogResult.OK){FileStream file_path = new FileStream(save_file.FileName, FileMode.OpenOrCreate,FileAccess.ReadWrite);BinaryWriter bin_write = new BinaryWriter(file_path);//創(chuàng)建BIN文件流byte[] init_byte = new byte[256];for (int temp = 0; temp < 256; temp++){init_byte[temp] = (byte)temp;}bin_write.Write(init_byte, 0, 256);//給BIN文件寫內(nèi)容bin_write.Flush();bin_write.Close();file_path.Close();}}}}文件運行結(jié)果為:
bin文件內(nèi)容
那么寫操作完成了,替換操作要怎么操作呢?實際中如果要實現(xiàn)HEX文件轉(zhuǎn)換為BIN文件,那么替換功能將會非常有用 , 比如將其中的某幾個數(shù)字改動一下,見代碼:
using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Windows.Forms;using System.IO;namespace TEST{public partial class Form1 : Form{public Form1(){InitializeComponent();}private void button1_Click(object sender, EventArgs e){SaveFileDialog save_file = new SaveFileDialog();save_file.Filter = "BIN文件|*.bin";if (save_file.ShowDialog() == DialogResult.OK)//打開文件對話框{FileStream file_path = new FileStream(save_file.FileName, FileMode.OpenOrCreate,FileAccess.ReadWrite);BinaryWriter bin_write = new BinaryWriter(file_path);//創(chuàng)建BIN文件流byte[] init_byte = new byte[256];for (int temp = 0; temp < 256; temp++){init_byte[temp] = (byte)temp;}bin_write.Write(init_byte, 0, 256);//初始化BIN文件Console.WriteLine(file_path.Length); //看一下目前文件大小bin_write.Seek(255, SeekOrigin.Begin);//修改BIN文件當(dāng)前位置至第255個字節(jié)bin_write.Write(0x08); //第255個字節(jié)改為08bin_write.Seek(8, SeekOrigin.Begin);//修改BIN文件當(dāng)前位置至第8個字節(jié)bin_write.Write((byte)0x01);//第8個字節(jié)改為01bin_write.Write((byte)0x02);//第9個字節(jié)改為02bin_write.Write((byte)(0x90));//第10個字節(jié)改為90byte[] buffer = new byte[8];for (int temp = 0; temp < 8; temp++){buffer[temp] = (byte)(temp + 1);}bin_write.Seek(128, SeekOrigin.Begin);//修改BIN文件當(dāng)前位置至第128個字節(jié)bin_write.Write(buffer, 2, 5);//將Buffer字節(jié)數(shù)組中的第2到到第7個數(shù)賦值到BIN文件的第128到133個字節(jié)bin_write.Write((byte)(0x90));//第134個字節(jié)改為08Console.WriteLine(file_path.Length);//看一下目前的文件大小file_path.SetLength(256);//文件大小已經(jīng)超過256 , 只保留256個字節(jié)Console.WriteLine(file_path.Length);//看一下目前的文件大小bin_write.Flush();//釋放文件資源bin_write.Close();file_path.Close();}}}}上述代碼的運行結(jié)果為:

推薦閱讀