读取bin文件,每次读取256个长度

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();
        }
    }
}