你怎么看在C#.NET二进制数据,然后将其转换为字符串? [英] How do you read binary data in C# .NET and then convert it to a string?

查看:498
本文介绍了你怎么看在C#.NET二进制数据,然后将其转换为字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

而不是使用的StreamReader /文件流我想从文件中读取二进制数据,并显示在一个文本框的数据(格式)。

As opposed to using StreamReader/Filestream I want to read binary data from files and show that data (formatted) in a textbox.

推荐答案

有不同的情况下,当一个人需要读取的二进制文件,因为它不清楚你真正想在这里实现一些:

There are different cases when one need to read binary file, since it is unclear what you really trying to achieve here are some:


  • 随机读取文件,并显示为一系列十六进制值(类似于Visual Studio或任何其他的二进制文件查看器二进制文件视图)。由杰夫·M的答案Berfectly覆盖。

  • 阅读和使用二进制序列写你自己的对象。在MSDN上检查序列化演练 - http://msdn.microsoft.com/en-us /library/et91as27.aspx 和BinaryFormatter的对象读取。

  • 阅读别人的二进制格式(如JPEG,PNG,ZIP,PDF)。在这种情况下,你需要知道文件的结构(你可以经常发现档案格式文件),并使用BinaryReader读取该文件的个别块。对于大多数常见的文件格式,很容易找到现有库,以便更方便易读取的方式等文件。在BinaryReader MSDN文章有基本的使用示例还:的http:// MSDN .microsoft.com / EN-US /库/ system.io.binaryreader.aspx

  • read random file and display as series of hex values (similar to binary file view in Visual Studio or any other binary file viewer). Berfectly covered by Jeff M's answer.
  • Reading and writing your own objects using binary serialization. Check serialization walkthrough on MSDN - http://msdn.microsoft.com/en-us/library/et91as27.aspx and read on BinaryFormatter objects.
  • Reading someone elses binary format (like JPEG, PNG, ZIP, PDF). In this case you need to know structure of the file (you can often find file format documentation) and use BinaryReader to read individual chunks of the file. For most of the common file formats it is easy to find existing libraries that allow reading such files in more convinient way. MSDN article on BinaryReader have basic usage sample also: http://msdn.microsoft.com/en-us/library/system.io.binaryreader.aspx.

这篇关于你怎么看在C#.NET二进制数据,然后将其转换为字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆