简体   繁体   English

文件流是否包含所有文件数据?

[英]Does a file stream contain all the file's data?

FileStream myFileStream = File.Open("C:\\file.txt", FileMode.Open);

This line declares and initializes a variable myFileStream, but what is exactly in this variable? 这行代码声明并初始化了一个变量myFileStream,但是该变量到底是什么? Does it contain all the bytes from "file.txt"? 它是否包含“ file.txt”中的所有字节? Or does it contain info about an established connection with the file? 还是包含有关与文件建立连接的信息?

It contains information about the established connection with the file. 它包含有关与文件建立的连接的信息。 Now when the connection is established and the file is opened, you can manipulate the text inside the file. 现在,当建立连接并打开文件时,您可以在文件中操作文本。

The variable myFileStream is just a HANDLE . 变量myFileStream只是一个HANDLE Nothing more. 而已。

You can use this HANDLE to access the file's contents or modify the the file's permissions with other Methods/Functions. 您可以使用此HANDLE来访问文件的内容,或使用其他方法/功能修改文件的权限。

On the binary level it's nothing more than a 32-bit/64-bit number used by the Operating System to reference to that file for being used by other Methods/Functions. 在二进制级别,它仅是操作系统用于引用该文件以供其他方法/功能使用的32位/ 64位数字。

So a simple answer to your question 所以简单回答你的问题

Does a FileStream contain all the file's data? FileStream是否包含所有文件数据?

is that it contains no data , but represents a HANDLE to access all of the file's data . 是它不包含任何数据 ,而是代表一个用来访问文件所有 数据HANDLE

As from Wikipedia definition In computer science, a stream is a sequence of data elements made available over time 摘自Wikipedia定义In computer science, a stream is a sequence of data elements made available over time

So your variable myFileStream is just a pointer that will allow you to manipulate a large amount of data 因此,变量myFileStream只是一个指针,可让您处理大量数据

may be you have to look for the difference between Stream and Buffer 可能是您必须寻找Stream和Buffer之间的区别

A buffer is normally just a block of memory where things can be stored in RAM. 缓冲区通常只是一块内存,可以将其存储在RAM中。

A stream is something that lets you store things on disk, send across to other computers such as the internet, serial port, UCB, etc. streams often use buffers to optimize transmission speed. 流是一种使您可以将内容存储在磁盘上并发送到其他计算机(例如Internet,串行端口,UCB等)的事物。流通常使用缓冲区来优化传输速度。

The FileStream object represents a handle to a representation of the file. FileStream对象表示文件表示形式的句柄 It acts as a reference to some underlying structure that is handled by your operating system which allows your code to ask the operating system for operations on the file that resides in your file system, such as Read , Write and Seek . 它充当对操作系统所处理的某些基础结构的引用,该基础结构允许您的代码向操作系统询问对驻留在文件系统中的文件的操作,例如ReadWriteSeek

What is important to keep in mind is that Stream s in general are abstract constructs (from the MSDN page on Streams ) that are designed for providing a clean interface to common operations on concepts that are similar, for example a File or a Socket . 要记住的重要一点是, Stream通常是抽象结构(来自StreamsMSDN页面 ),旨在为类似概念的常见操作(例如FileSocket )提供干净的接口。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM