我的要求是记录用户语音并将其保存在服务器上(同时多个用户)。这是我的代码:
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)
谢谢
答案 0 :(得分:0)
不要关闭InputStream对象。
Thumb规则:如果您尚未打开连接或流,请不要关闭它。
注释掉in.close()