Reputation: 15146
If I had a directory filled with different object files, is there a way I could input them into my application without opening a new stream every time? I am currently using ObjectInputStream
, but I don't mind using another form of IO.
For example, if I stored my users directly onto my harddrive as objects (each having their own file: name.user), is there a way I could load them all back in using the same stream? Or would it be impossible seeing how a new File
object would be needed for each individual file? Is there a way around this?
Upvotes: 0
Views: 66
Reputation: 20520
Each file will need its own stream behind the scenes; there's no way round that. But that doesn't stop you creating your own InputStream
that manages this for you, and then allows you to read everything off from one stream.
The idea would be that when you try to read from your CompoundObjectInputStream
or whatever, it looks to see if there are any more files that it hasn't yet processed, and opens one if so using another stream, and passes the data through. When it reaches the point where there are no more files in that directory, the CompoundObjectInputStream
indicates end-of-stream.
Upvotes: 2
Reputation: 280138
No, there is not. Each physical file requires its own FileInputStream
, FileChannel
, or other corresponding native
accessor.
Note that File
has no direct link to a physical file, it is just an abstract path name.
Upvotes: 1