我是一个取客户端发过来信息的方法,在JSP页面里面 -----------代码----------- private byte[] ReadPackage(HttpServletRequest request) { ServletInputStream sis=null; byte mStream[]=null; int totalRead = 0; int readBytes = 0; int totalBytes = 0; try { totalBytes = request.getContentLength(); sis = request.getInputStream(); mStream = new byte[totalBytes]; while(totalRead < totalBytes) { readBytes = sis.read(mStream, totalRead, totalBytes - totalRead); // request.getInputStream().read(mStream, totalRead, totalBytes - totalRead); totalRead += readBytes; } } catch (Exception e) { System.out.println(e.toString()); } finally{ sis.close(); } return (mStream); }-----------报错信息----------- "OfficeServer.jsp": Error #: 360 : unreported exception: java.io.IOException; must be caught or declared to be thrown at line 101
catch (Exception e) { System.out.println(e.toString()); } finally{ sis.close(); } return (mStream); } 当你关闭 sis.close();时候也会抛出一个异常所以你要在这里加上try{}catch(){}看api 里的定义: close public void close() throws IOException Closes this input stream and releases any system resources associated with the stream. The close method of InputStream does nothing. Throws: IOException - if an I/O error occurs.
try
{
ServletInputStream obj =new ....();
}
finally
{
if (obj!=null)
obj.close();
}
-----------代码-----------
private byte[] ReadPackage(HttpServletRequest request)
{
ServletInputStream sis=null;
byte mStream[]=null;
int totalRead = 0;
int readBytes = 0;
int totalBytes = 0; try
{
totalBytes = request.getContentLength();
sis = request.getInputStream();
mStream = new byte[totalBytes];
while(totalRead < totalBytes)
{
readBytes = sis.read(mStream, totalRead, totalBytes - totalRead); // request.getInputStream().read(mStream, totalRead, totalBytes - totalRead);
totalRead += readBytes;
}
}
catch (Exception e)
{
System.out.println(e.toString());
}
finally{
sis.close();
}
return (mStream);
}-----------报错信息-----------
"OfficeServer.jsp": Error #: 360 : unreported exception: java.io.IOException; must be caught or declared to be thrown at line 101
{
System.out.println(e.toString());
}
finally{
sis.close();
}
return (mStream);
}
当你关闭 sis.close();时候也会抛出一个异常所以你要在这里加上try{}catch(){}看api 里的定义:
close
public void close()
throws IOException
Closes this input stream and releases any system resources associated with the stream.
The close method of InputStream does nothing.
Throws:
IOException - if an I/O error occurs.