Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do you think the Java language chooses to treat file data as a stream rather than as a single object?

Tags:

java

file

Why do you think the Java language chooses to treat file data as a stream rather than as a single object? What are the benefits of this approach?

like image 751
John85 Avatar asked Dec 22 '22 04:12

John85


2 Answers

Consider loading a 4 GB file into your application as an object....

If thats not good enough consider handling 50 of those files simultanously and think about how much memory that would require.

Btw there is a high level File class for doing high level operations.

like image 82
Udo Held Avatar answered Dec 24 '22 02:12

Udo Held


The answer depends on how you define "a stream" and a "single object".

Assuming that random access is what distinguishes the two, the answer is that the abstraction of streams is more general and supports not only disk files, but also sockets, pipes and other communication channels.

like image 35
Adam Zalcman Avatar answered Dec 24 '22 02:12

Adam Zalcman