Afzaal Ahmad Zeeshan 9-Sep pm. Updated your question to make it a candidate for my vote of 5. Hope that you don't mind. This is a wrong, totally wrong question, as nearly all questions about "difference". In this particular case, this is the same as asking "what is the difference between penguin and bird? You really need to learn the basics of OOP.
In particular, you need to understand the compile-time types vs runtime types. In your first line, the constructor returns an instance of FileStream as any constructor of the same time would do , but you abstract it up to the compile-time type Stream. Nevertheless, runtime type of the variable s is still FileStream. And so on… Mind you, we are only discussing some prerequisites to OOP, but the "real" OOP plays fundamental role in these types; so you need to learn all those prerequisites encapsulation, inheritance, and so on really well, before you can really do any programming.
Posted 9-Sep am Sergey Alexandrovich Kryukov. Excellent answer, 5ed. I had the same answer in mind, but yours of penguin-bird is better! Sergey Alexandrovich Kryukov 9-Sep pm. Thank you, Afzaal. I knew that penguins rule. A bad analogy to start Imagine a water desalination plant something that takes seawater, removes the salt and outputs clean drinking water to the water network : The desalination plant can't remove the salt from all of the sea at one time and nor would we want it to… where would the saltwater fish live?
That SeaStream is connected to the DesalinationStream to remove the salt And the output of the DesalinationStream is connected to the DrinkingWaterNetworkStream to output the now saltless water to the drinking water supply. OK, so what's that got to do with computers? Moving big files all at once can be problematic Frequently in computing we want to move data between two locations, e. It can be better to split the file and move it a piece at a time So, rather than getting whole file at once, it would be better to retrieve the file a piece at a time and pass each piece on to the destination one at a time.
This is what a Stream does and that's where the two different types of stream you mentioned come in: We can use a FileStream to retrieve data from a file a piece at a time and the database API may make available a MemoryStream endpoint we can write to a piece at a time.
We connect those two 'pipes' together to flow the file pieces from file to database. The stages we we're carrying out were: Retrieving the data from the disk slow Writing to a File object in the computer's memory a bit faster Reading from that File object in the computer's memory faster again Writing to the database probably slow as there's probably a spinning disk hard-drive at the end of that pipe Streams allow us to conceptually do away with the middle two stages, instead of dragging the whole file into computer memory at once, we take the output of the operation to retrieve the data and pipe that straight to the operation to pass the data onto the database.
Other benefits of streams Separating the retrieval of the data from the writing of the data like this also allows us to perform actions between retrieving the data and passing it on. Tags: C Filestream Memorystream. Shortest Hello World program with no semi colons Update. Ask Question. Asked 7 years, 10 months ago. Active 2 years ago.
Viewed 10k times. Can anybody explain what exactly streams are, and how they relate to files? Improve this question. Antti Haapala k 21 21 gold badges silver badges bronze badges. What is your understanding till time? Did you though of using google? Can you provide context for that quote? It is unclear what it is referring to; if you read it in a book, more context may help us clarify it better. Not all files have same capabilities.
Stream is a representation of flow of data from one side to another e. File is a representation to store data on disk file. File uses streams to store and load data. Monday, May 18, AM.
File Class:Provides static methods for the creation, copying, deletion, moving, and opening of files, and aids in the creation of FileStream objects. File class for typical operations such as copying, moving, renaming, creating, opening, deleting, and appending to files. So where the buffer resides? Thanks for the help! L Hashim 0. Net Goodies Remember to click "mark as answered" when you get a correct reply to your question. Yea,you are right. FileStream Class 2. MemoryStream Class 3.
0コメント