views:

234

answers:

3

I try to open a large number of files but after 5000 files or so I get

Exception in thread "Main" java.io.IOException: The device is not connected


Is this the expected behavior? Is there a way around it? I want to leave my code as straightforward as possible.

A: 

An open file has some cost in resources, so that opening another file fails when many files are already open is expected behavior. At least it is expecte by myself.

see for example this: http://www.msfn.org/board/lofiversion/index.php/t101414.html

Jens Schauder
A: 

It should not be a problem opening thousands of files if you remember to close() your files when you are done using them?

If not, you force the operating system to maintain state for your open files, which usually is a limited resource.

If you really need lots of simultaneous open files, the solution depends on the circumstances. What is it you need to do? Please show code.

Thorbjørn Ravn Andersen
A: 
  • Your operating system may limit the number of files one process can have open.
  • Generally you want to be careful with resources like open files in java. Unless you have a specific reason for keeping all of those open, you'd be better off reading through each file, extracting the data you want, and then closing.

What exactly are you trying to achieve?

Steve B.