我的代码:(可以不用看)
String path = getClass().getResource("").getPath();
int index = path.lastIndexOf("WEB-INF");
path = path.substring(1, index);
path = path + "upload/";
String contentType = request.getContentType();
int contentTypeLength = request.getContentLength();
int boundaryIndex = contentType.indexOf("boundary=");
String boundary = contentType.substring(boundaryIndex + 9);
int boundaryStrLength = boundary.length(); ServletInputStream serIn = request.getInputStream();
int line;
byte[] buffer = new byte[4096];
while ((line = serIn.readLine(buffer, 0, contentTypeLength)) != -1) {
if (buffer[0] == 13 | buffer[0] == 10)
break;
}
ByteArrayOutputStream byteOut = new ByteArrayOutputStream(
contentTypeLength);
int len;
while ((len = serIn.read(buffer)) >= 0) {
byteOut.write(buffer, 0, len);
}
byte[] outBytes = byteOut.toByteArray();
BufferedOutputStream fileOut = new BufferedOutputStream(
new FileOutputStream(path + "uploaded_file"));
fileOut.write(outBytes, 0, outBytes.length - boundaryStrLength - 8);
fileOut.flush();
fileOut.close();
String path = getClass().getResource("").getPath();
int index = path.lastIndexOf("WEB-INF");
path = path.substring(1, index);
path = path + "upload/";
String contentType = request.getContentType();
int contentTypeLength = request.getContentLength();
int boundaryIndex = contentType.indexOf("boundary=");
String boundary = contentType.substring(boundaryIndex + 9);
int boundaryStrLength = boundary.length(); ServletInputStream serIn = request.getInputStream();
int line;
byte[] buffer = new byte[4096];
while ((line = serIn.readLine(buffer, 0, contentTypeLength)) != -1) {
if (buffer[0] == 13 | buffer[0] == 10)
break;
}
ByteArrayOutputStream byteOut = new ByteArrayOutputStream(
contentTypeLength);
int len;
while ((len = serIn.read(buffer)) >= 0) {
byteOut.write(buffer, 0, len);
}
byte[] outBytes = byteOut.toByteArray();
BufferedOutputStream fileOut = new BufferedOutputStream(
new FileOutputStream(path + "uploaded_file"));
fileOut.write(outBytes, 0, outBytes.length - boundaryStrLength - 8);
fileOut.flush();
fileOut.close();
解决方案 »
- ExtJs修改树形结点的Icon?
- 帮忙看看,自己写的加密算法,有乱码问题
- 求救~struts2.0与spring和hibernate整合之后又要与jquery、
- 在JSP页面中调用jfreechart生成的图片乱码解决方案
- 何时使用触发器的问题??
- 简单的hibernate问题,关于*.hdb.xml文件
- hibernate 中,删除一个查询出来的对象和删除一个new出来的对象,有什么区别
- 附件带的是HTML或HTM文件,为什么是在页面显示,而不是提供下载的呢?
- 100分求救!!!!!!!!
- 我们为什么要用EJB?
- dao层或者Service层,设为static可以吗?
- 怎么去掉重复值谢谢!
-----------------------------7da2de1c1c07e4
Content-Disposition: form-data; name="foo"; filename="tt.rar"
Content-Type: application/octet-stream