为什么我得到java.io.IOException:Stream关闭了?

时间:2012-01-23 08:01:30

标签: java inputstream

我正在尝试下载一个zip文件,但我收到了 Stream Closed Exception 。 当我使用摇摆gui它得到这个错误,但如果我使用控制台没有问题。 为什么我会得到这个例外?我该如何解决?

这是我的代码:

URLConnection conn = url.openConnection();
InputStream in = conn.getInputStream();
FileOutputStream out = new FileOutputStream(destination.getPath());
byte[] b = new byte[1024];
int count;

while ((count = in.read(b)) >= 0) {
    out.write(b, 0, count);
}
out.flush();
out.close();
in.close();
OptionPane.showMessageDialog(null, "Download is finished");
} catch (HttpUnauthorizedException e) {
    JOptionPane.showMessageDialog(null, "Proxy or Server Authentication Required");
} catch (IOException e) {
    System.out.println(e.getMessage());
}

这是堆栈跟踪

java.io.IOException: Stream closed.
at java.net.PlainSocketImpl.available(PlainSocketImpl.java:428)
at java.net.SocketInputStream.available(SocketInputStream.java:217)
at java.io.BufferedInputStream.read(BufferedInputStream.java:321)
at weblogic.net.http.KeepAliveStream.read(KeepAliveStream.java:86)
at java.io.FilterInputStream.read(FilterInputStream.java:90)
at be.azvub.ext.bcfidownloder.Download.downloadZipFile(Download.java:130)
at be.azvub.ext.bcfidownloder.Download.authorize(Download.java:91)
at be.azvub.ext.bcfidownloder.BcfiDownloadPanel$4.mouseClicked(BcfiDownloadPanel.java:110)
at java.awt.AWTEventMulticaster.mouseClicked(AWTEventMulticaster.java:212)
at java.awt.Component.processMouseEvent(Component.java:5520)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3129)
at java.awt.Component.processEvent(Component.java:5282)
at java.awt.Container.processEvent(Container.java:1966)
at java.awt.Component.dispatchEventImpl(Component.java:3984)
at java.awt.Container.dispatchEventImpl(Container.java:2024)
at java.awt.Component.dispatchEvent(Component.java:3819)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4212)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3901)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3822)
at java.awt.Container.dispatchEventImpl(Container.java:2010)
at java.awt.Window.dispatchEventImpl(Window.java:1791)
at java.awt.Component.dispatchEvent(Component.java:3819)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:463)
at be.azvub.webutil.gui.WebEventQueue.dispatchEvent(WebEventQueue.java:34)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:242)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:163)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:157)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:149)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)

3 个答案:

答案 0 :(得分:4)

此异常通常意味着连接突然关闭。我会查看服务器上的日志,看看是否有错误。

答案 1 :(得分:0)

可能是由于JVM延迟,可能是因为unix / linux操作系统的随机数生成器引起的。您应该用/ dev /./ urandom

替换它

此链接有更多详细信息。

http://devcorn.com/java-io-ioexception-stream-closed-no-available-router-to-destination/

答案 2 :(得分:0)

我从xhtml中删除了Primefaces的这个标签时解决了它。

<p:media ...

来源

http://www.primefaces.org/showcase/ui/multimedia/media.xhtml