0
我想知道是否有创建一个字节[]的内容写入ServletOutputStream的特定规则或最佳做法?应写入ServletOutPutStream的字节
byte[] buffer = new byte[1024];
int r = 0;
try {
in = new BufferedInputStream(new FileInputStream(new File("/path/to/the/some/file")));
sos = response.getOutputStream();
while ((r = in.read(buffer, 0, buffer.length)) != -1) {
sos.write(buffer, 0, r);
在上面的代码,字节[] lenth是1024。如果我跑我的tomcat中的servlet,我需要的缓冲区的长度与Tomcat的缓冲区的匹配吗?或者它并不重要? Tomcat的默认缓冲区大小可能是4096,而我的字节[]可以说是20000
不知道问题是否有意义,但自从我在代码中增加了byte []长度后,我得到了indexoutofboundsexception。此前字节[]长度为1KB,我改成了64KB和我开始IndexOutOfBoundsException异常
如果它确实是防弹的,那么为什么不呢。感谢提示 – user305210 2011-02-08 18:44:09