Java File Upload key code

Source: Internet
Author: User

Tag:ipa    Code    nbsp   filename   head     maximum    parse   write   zemax   

  File Upload
# #前台:
Form form submit, form Add Style enctype= "Multipart/form-data" method= "post";
# #后台
//string path for the server to save files for
Diskfileitemfactory factory = new Diskfileitemfactory ();
Factory.setsizethreshold (5*1024);//Cache
Factory.setrespository (new file (TempPath));//Temporary file path
Servletfileupload upload = new Servletfileupload (factory);
Upload.setheaderencoding ("UTF-8");
Upload.setsizemax (8888*1024*1024);//Set maximum

list<fileitem> items = upload.parserequest (request);
Fileitem item = items.get (i);
if (!item.isformfield ()) {
FileName = item.getname ();             
string[] str = filename.split ("\ \");
String fileType = str[str.lenth-1];

InputStream in = Item.getinputstream ();//Read data written to file
FileOutputStream out = new FileOutputStream (path);
byte buffer[] = new byte[1024];
int len = 0;
while ((Len=in.read (buffer)) >0) {
Out.write (Buffer,0len);
}
Item.delete ();
}

Java File upload key code

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.