Dani
Dani

Reputation: 4447

The device is not connected exception

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.

Upvotes: 0

Views: 1848

Answers (3)

Steve B.
Steve B.

Reputation: 57324

  • 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?

Upvotes: 1

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.

Upvotes: 0

Jens Schauder
Jens Schauder

Reputation: 81950

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

Upvotes: 0

Related Questions