0

我的要求是录制用户语音并将其保存在服务器上(同时多个用户)。这是我的代码:

in = (InputStream) request.getInputStream();                         
fos = new FileOutputStream(f1);
int read = 0;
while ((read = in.read()) != -1) {
    fos.write(read);
}
fos.close();
in.close();

尝试一次为多个用户录制语音时出现以下异常,单个用户没有出现此异常:

java.io.IOException: Stream closed
    at org.apache.catalina.connector.InputBuffer.readByte(InputBuffer.java:315)
    at org.apache.catalina.connector.CoyoteInputStream.read(CoyoteInputStream.java:105)
    at CommonPackage.Upload.processRequest(Upload.java:78)
    at CommonPackage.Upload.doPost(Upload.java:115)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
    at org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:877)
    at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:594)
    at org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1675)
    at java.lang.Thread.run(Thread.java:619)

谢谢

4

1 回答 1

0

不要关闭 InputStream 对象。

经验法则:如果您尚未打开连接或流,请不要关闭它。

注释掉 in.close()

于 2013-09-26T08:12:58.307 回答