Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How Java IO loads data ?  RSS feed

 
Mani vannan
Ranch Hand
Posts: 185
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
For long days I have this doubt: When I open a java stream to read a file (Ex: in Size 10 MB), whether all the contents of file loaded in Memory? Or it loads a partial content on demand? Please some body clarify this issues.
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
BufferedInputStream reads a buffer full of input at a time. It can read ahead of what you have asked for. I always assumed that InputStream reads only the number you ask for - from one to an array full. Buffered is usually much faster, so we can guess that it's doing fewer and larger physical IO calls. Is that the kind of thing you were interested in?
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Everything Stan says is correct, but I wanted to add one thing: no, Java doesn't read your whole 10 MB file into RAM as soon as you open it. When you open a file, Java doesn't read any of the data at all. None of the data is read until something calls read().
 
Mani vannan
Ranch Hand
Posts: 185
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
oh, thanks for ur replies and now I am clear.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!