資源簡介
版本:VS2010
C#讀取bin文件,并顯示在TextBox控件內

代碼片段和文件信息
using?System;
using?System.Collections.Generic;
using?System.ComponentModel;
using?System.Data;
using?System.Drawing;
using?System.Linq;
using?System.Text;
using?System.Windows.Forms;
using?System.IO;
namespace?open_bin
{
????public?partial?class?Form1?:?Form
????{
????????public?Form1()
????????{
????????????InitializeComponent();
????????}
????????private?void?button1_Click(object?sender?EventArgs?e)
????????{
????????????string?Mytext?=?““;
????????????int?file_len;
????????????int?read_len;
????????????byte[]?binchar?=?new?byte[]?{?};
????????????FileStream?Myfile?=?new?FileStream(“test.bin“?FileMode.Open?FileAccess.Read);
????????????BinaryReader?binreader?=?new?BinaryReader(Myfile);
????????????file_len?=?(int)Myfile.Length;//獲取bin文件長度
????????????while?(file_len?>?0)
????????????{
????????????????if?(file_len?/?256?>?0)//一次讀取256字節
????????????????????read_len?=?256;
????????????????else???????????????????//不足256字節按實際長度讀取
????????????????????read_len?=?file_len?%?256;
????????????????binchar?=?binreader.ReadBytes(read_len);
????????????????foreach?(byte?j?in?binchar)
????????????????{
????????????????????Mytext?+=?j.ToString(“X2“);
????????????????????Mytext?+=?“?“;
????????????????}
????????????????file_len?-=?read_len;
?????????????}
????????????textBox1.Text?=?Mytext;
????????????binreader.Close();
????????}
????}
}
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???????8704??2014-06-26?15:32??open_bin\open_bin\bin\Debug\open_bin.exe
?????文件??????24064??2014-06-26?15:32??open_bin\open_bin\bin\Debug\open_bin.pdb
?????文件??????11600??2014-06-26?15:32??open_bin\open_bin\bin\Debug\open_bin.vshost.exe
?????文件????????490??2012-06-02?22:34??open_bin\open_bin\bin\Debug\open_bin.vshost.exe.manifest
?????文件??????19348??2014-06-24?10:28??open_bin\open_bin\bin\Debug\test.bin
?????文件???????1460??2014-06-26?15:32??open_bin\open_bin\Form1.cs
?????文件???????2642??2014-06-26?15:16??open_bin\open_bin\Form1.Designer.cs
?????文件???????5817??2014-06-26?15:16??open_bin\open_bin\Form1.resx
?????文件???????5420??2014-06-24?16:55??open_bin\open_bin\obj\x86\Debug\DesignTimeResolveAssemblyReferences.cache
?????文件???????6308??2014-06-26?15:32??open_bin\open_bin\obj\x86\Debug\DesignTimeResolveAssemblyReferencesInput.cache
?????文件????????634??2014-06-26?15:32??open_bin\open_bin\obj\x86\Debug\open_bin.csproj.FileListAbsolute.txt
?????文件????????975??2014-06-26?15:16??open_bin\open_bin\obj\x86\Debug\open_bin.csproj.GenerateResource.Cache
?????文件???????9174??2014-06-25?09:13??open_bin\open_bin\obj\x86\Debug\open_bin.csprojResolveAssemblyReference.cache
?????文件???????8704??2014-06-26?15:32??open_bin\open_bin\obj\x86\Debug\open_bin.exe
?????文件????????180??2014-06-26?15:16??open_bin\open_bin\obj\x86\Debug\open_bin.Form1.resources
?????文件??????24064??2014-06-26?15:32??open_bin\open_bin\obj\x86\Debug\open_bin.pdb
?????文件????????180??2014-06-24?11:03??open_bin\open_bin\obj\x86\Debug\open_bin.Properties.Resources.resources
?????文件???????3675??2014-06-24?11:03??open_bin\open_bin\open_bin.csproj
?????文件????????489??2014-06-24?10:52??open_bin\open_bin\Program.cs
?????文件???????1348??2014-06-24?10:52??open_bin\open_bin\Properties\AssemblyInfo.cs
?????文件???????2868??2014-06-24?10:52??open_bin\open_bin\Properties\Resources.Designer.cs
?????文件???????5612??2014-06-24?10:52??open_bin\open_bin\Properties\Resources.resx
?????文件???????1095??2014-06-24?10:52??open_bin\open_bin\Properties\Settings.Designer.cs
?????文件????????249??2014-06-24?10:52??open_bin\open_bin\Properties\Settings.settings
?????文件????????866??2014-06-24?10:52??open_bin\open_bin.sln
????..A..H.?????19968??2014-06-26?15:32??open_bin\open_bin.suo
?????目錄??????????0??2014-06-24?10:52??open_bin\open_bin\obj\x86\Debug\TempPE
?????目錄??????????0??2014-06-26?15:32??open_bin\open_bin\obj\x86\Debug
?????目錄??????????0??2014-06-26?15:19??open_bin\open_bin\bin\Debug
?????目錄??????????0??2014-06-24?10:52??open_bin\open_bin\obj\x86
............此處省略8個文件信息
- 上一篇:C#直接讀寫西門子PLC類庫——S7.net
- 下一篇:C#編寫的QQ簡單界面源代碼
評論
共有 條評論