我之前的帖子被删除了,所以我在这里重新发布,因为我没有任何线索可以删除这个错误。
错误 :
java.lang.IndexOutOfBoundsException
java.io.FileOutputStream.writeBytes(Native Method)
java.io.FileOutputStream.write(FileOutputStream.java:297)
com.ninenexus.simplesign.storeanddisplay.StoreAndDisplayImage.doPost(StoreAndDisplayImage.java:85)
javax.servlet.http.HttpServlet.service(HttpServlet.java:754)
javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
代码 :
String contentType = request.getContentType();
if ((contentType != null)
&& (contentType.indexOf("multipart/form-data") >= 0))
{
DataInputStream in = new DataInputStream(request.getInputStream());
int formDataLength = request.getContentLength();
byte dataBytes[] = new byte[formDataLength];
int byteRead = 0;
int totalBytesRead = 0;
while (totalBytesRead < formDataLength)
{
byteRead = in.read(dataBytes, totalBytesRead, formDataLength);
totalBytesRead += byteRead;
}
String file = new String(dataBytes);
saveFile = file.substring(file.indexOf("filename=\"") + 10);
saveFile = saveFile.substring(0, saveFile.indexOf("\n"));
saveFile = saveFile.substring(saveFile.lastIndexOf("\\") + 1,
saveFile.indexOf("\""));
int lastIndex = contentType.lastIndexOf("=");
String boundary = contentType.substring(lastIndex + 1,
contentType.length());
int pos;
pos = file.indexOf("filename=\"");
pos = file.indexOf("\n", pos) + 1;
pos = file.indexOf("\n", pos) + 1;
pos = file.indexOf("\n", pos) + 1;
int boundaryLocation = file.indexOf(boundary, pos) - 4;
int startPos = ((file.substring(0, pos)).getBytes()).length;
int endPos = ((file.substring(0, boundaryLocation)).getBytes()).length;
saveFile = "d:/" + saveFile;
try
{
File f = new File(saveFile);
FileOutputStream fileOut = new FileOutputStream(f);
fileOut.write(dataBytes, startPos, (endPos - startPos)); // Line 85
fileOut.flush();
fileOut.close();
}
catch(...)
{
...
}
}
else
{
...
}
行号的输出。85 是
dataBytes=[B@676e3f, startPos=142, (endPos - startPos)=75944.
我正在尝试通过输入 type='file' 从用户那里获取文件,然后使用此代码将其保存在目录中。它在tomcat服务器上运行良好。文件保存在目录中。但是当我创建战争文件并将其上传到服务器上时。尝试在主服务器上运行此代码时出现此错误。没有解决这个问题的线索。帮助真的很感激。