简体   繁体   English

为什么这里出现“打开文件过多”错误

[英]why “too many open file” error occured here

In my Java Application, I have around 30 Java files which have ObjectOutputStreams and ObjectInputStreams. 在我的Java应用程序中,我大约有30个Java文件,这些文件包含ObjectOutputStreams和ObjectInputStreams。 but I never close those streams in anywhere. 但是我从来没有在任何地方关闭这些流。 The application is working fine for some time, after a week or so, I am getting too many files open error. 该应用程序在一段时间内运行良好,大约一周后,我收到太多文件打开错误消息。 Is this because of not closing the streams or anything else? 这是因为没有关闭流或其他原因吗?

Please help me out in better understanding the issue.... 请帮助我更好地理解这个问题。

Any stream has to be CLOSED after usage in a try catch / with fianlly(to close here) or try-with-resources, for being sure it gets closed since it implements Closable interface. 在try catch /中使用fianlly(在此处关闭)或try-with-resources后,必须关闭任何流,以确保由于实现了Closable接口而将其关闭。 http://www.javapractices.com/topic/TopicAction.do?Id=8 http://www.javapractices.com/topic/TopicAction.do?Id=8

  try {
      // open stream
      // use stream

    } catch(IOException e) {
      // handle exceptions
    }
    finally{
      // try-catch closing( for multiple clsoes mainly)
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM