Get the input stream of a file in a java program, such as the input stream of a 50M text file. At this time, has the program loaded the entire file into the memory? Has it occupied 50M of space in memory? Or is there just one entrance, and when it is necessary to loop through the contents, the contents of the file are loaded one by one?
The whole thing is not loaded into the memory, but some bytes can be loaded into the cache through the buffer. The whole thing is not loaded into the memory, but some bytes can be loaded into the cache through the buffer
If you just open the input stream without reading it, the file does not occupy memory. Only when the file content is read, the memory will be used accordingly, as much as you read.
It can be loaded into memory through buffering, and this is also the case in the operating system.