//新建一个文件对话框
OpenFileDialog pOpenFileDialog = new OpenFileDialog();
//设置对话框标题
pOpenFileDialog.Title = "打开二进制文件";
//设置打开文件类型
pOpenFileDialog.Filter = "bin文件(*.*)|*.*";
//监测文件是否存在
pOpenFileDialog.CheckFileExists = true;
//文件打开后执行以下程序
if (pOpenFileDialog.ShowDialog() == DialogResult.OK)
{
System.IO.Path.GetFullPath(pOpenFileDialog.FileName); //绝对路径
System.IO.Path.GetExtension(pOpenFileDialog.FileName); //文件扩展名
System.IO.Path.GetFileNameWithoutExtension(pOpenFileDialog.FileName);//文件名没有扩展名
System.IO.Path.GetFileName(pOpenFileDialog.FileName); //得到文件
System.IO.Path.GetDirectoryName(pOpenFileDialog.FileName); //得到路径
}
FileStream inStream = new FileStream(pOpenFileDialog.FileName,FileMode.Open,FileAccess.Read);
long nBytesToRead = inStream.Length;
buffer = new byte[nBytesToRead];
int m=inStream.Read(buffer,0,buffer.Length);
inStream.Close();
//显示到richtextbox1 控件中,并且用 隔开
richTextBox1.Clear();
for(int i=0;i<buffer.Length;i++)
{
richTextBox1.AppendText(buffer[i].ToString("X2")+" ");
}
原文地址:https://www.cnblogs.com/mainmaster/p/12002714.html