ormFile file = uploadForm.getFile();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
InputStream stream = file.getInputStream();
OutputStream bos = new FileOutputStream("C:\111");
int bytesRead = 0;
byte[] buffer = new byte[8192];
while ((bytesRead = stream.read(buffer, 0, 8192)) != -1) {
bos.write(buffer, 0, bytesRead);
}
bos.close();
stream.close();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
InputStream stream = file.getInputStream();
OutputStream bos = new FileOutputStream("C:\111");
int bytesRead = 0;
byte[] buffer = new byte[8192];
while ((bytesRead = stream.read(buffer, 0, 8192)) != -1) {
bos.write(buffer, 0, bytesRead);
}
bos.close();
stream.close();
try{
SmartUpload upload = new SmartUpload();
upload.initialize(pageContext);
upload.upload();
for (int i=0;i<upload.getFiles().getCount();i++){
com.jspsmart.upload.File newFile = upload.getFiles().getFile(i);
if (!newFile.isMissing()) {
newFile.saveAs("d:/websrc/upload/newFileName" );//修改你的存储路径
out.println("FieldName = " + newFile.getFieldName() + "<BR>");
out.println("Size = " + newFile.getSize() + "<BR>");
out.println("FileName = " + newFile.getFileName() + "<BR>");
} }
}catch(Exception e){
out.println(e.toString());
}
%>
</body>
<BODY BGCOLOR="WHITE">
<FONT SIZE="2" FACE="Arial">
<CENTER>
<HR>
<H1>File Upload Test</H1>
<HR>
</CENTER>
<FORM METHOD="POST" ACTION="http://localhost:8080/test/servlet/fileup" ENCTYPE="multipart/form-data">
FILE <INPUT TYPE=FILE NAME="dataFile"><BR>
TEXT 1: <INPUT TYPE=TEXT NAME=text1><BR>
<INPUT TYPE=SUBMIT>
</FORM>
</FONT>
</BODY></HTML>
*上面的是jsp文件,upload.jsp
*下面的是html文件
*/<HTML>
<HEAD></HEAD>
<BODY>
<form name="form1" method="post" enctype="multipart/form-data" action="upload.jsp" >
<input type="file" name="file" class="textbox" size="30">
<input type=submit name=submit value="submit"></form>
</BODY>
</HTML>