从文件中读取一个字节而不打开它 [英] Reading a byte from the file without opening it

查看:133
本文介绍了从文件中读取一个字节而不打开它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我可以在不打开文件的情况下从文件中读取字节吗?根据我想在这里做的事情,这可能会有些混乱.读取文件中任何位置的字节,而不考虑要从中读取字节的文件的大小.
文件大小理论上可以为256TB,因为它是NTFS限制.
谢谢

Hi,
Can I read a byte from a file without opening it. It might be a little confusing as per what I want to do here. To read a byte at any position in a file regardless of the size of the file from which the byte is being read.
The file size could theoretically be 256TB, as it is the NTFS limit.
Thanks

推荐答案

否.

为了从文件内容中获取任何信息,甚至是单个字节,都必须打开文件.
但是,一旦打开,就完全有可能直接对文件中的任何字节进行寻址-Stream.Position属性和Stream.Seek方法都使用long值,而不是int,因此寻址不应为问题.

话虽如此,我还没有尝试过-我没有任何1TB的单个文件可供检查! :laugh:
No.

In order to get any information from the file content, even a single byte, you have to open the file.
However, once it is open, it should be perfectly possible to address any byte in teh file directly - both the Stream.Position property and the Stream.Seek method use long values, not int, so addressing should not be a problem.

Having said that, I haven''t tried it - I don''t have any 1TB single files sitting around to check with! :laugh:


我会尝试在较低级别解决该任务.通俗地说,打开"文件仅意味着我从操作系统中的文件系统驱动程序获取了一个句柄,并且在我所有的文件操作中,我都在使用该驱动程序和获得的句柄.
但是,当然,您可以编写自己的工具来绕过驱动程序访问文件系统.您可以编写自己的驱动程序,但也可以依靠一些底层api函数直接读取文件系统.当然,要执行此操作,您需要某些特权,并且我不确定是否可以在托管代码中执行此操作.

即使这是不受管理的,我也将从这里开始:
NTFS解析器库 [
I would try to address the task on a lower level. "Opening" a file in common terms means only that I acquire a handle from a file system driver in the operating system, and in all my file operations I am using this driver and the handle I got.
But of course you can write your own tools to access the file system bypassing the driver. You can write your own driver, but also rely on some low level api functions to read the file system directly. Of course, to do this you need certain privileges, and I am not sure if you will be able to do this in managed code.

I would start from here, even if this is unmanaged:
An NTFS Parser Lib[^]

Good luck!


这篇关于从文件中读取一个字节而不打开它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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