1

If I have 2 inputStream objects that read/holds a 4gb and 4mb of file respectively. what will be the size of the objects? will the size of object depends of the content?

I am facing the per gem error while processing huge size of Excel files.

trincot
  • 317,000
  • 35
  • 244
  • 286
Chowdappa
  • 1,580
  • 1
  • 15
  • 31

1 Answers1

5

An object of type InputStream needs just a few bytes, no matter how big the underlying stream is. For a file, it just remembers the OS's file descriptor which in turn tracks the current position in the file.

For large files, I suggest to use BufferedInputStream which needs more memory but it's also faster. You can define the buffer size when you create an instance, the default is 8KB which is good for most purposes.

That said, PermGen errors are unrelated to object sizes. Objects are allocated on the heap. PermGen means that you're loading too many classes. See Dealing with "java.lang.OutOfMemoryError: PermGen space" error for details how to fix it.

Community
  • 1
  • 1
Aaron Digulla
  • 321,842
  • 108
  • 597
  • 820