Home  >  Q&A  >  body text

The relationship between obtaining file input stream and memory usage in JAVA

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?

三叔三叔2683 days ago972

reply all(3)I'll reply

  • 欧阳克

    欧阳克2017-06-15 09:23:27

    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

    reply
    0
  • 淡淡烟草味

    淡淡烟草味2017-06-15 09:23:27

    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.

    reply
    0
  • 漂亮男人

    漂亮男人2017-06-15 09:23:27

    It can be loaded into memory through buffering, and this is also the case in the operating system.

    reply
    0
  • Cancelreply