Java simple File Upload

Source: Internet
Author: User

/*
* Rename the File Uploaded from the form.
*/
Private String getNewFilename (String s ){
Int I = s. indexOf (".");
String s1 = s. substring (I + 1, s. length ());
Java. util. Date today = new java. util. Date ();
String str = "";
// SimpleDateFormat, which is under the java. text package, converts a data object to the string we want
SimpleDateFormat formatter = new SimpleDateFormat ("yyyyMMddHHmmssSSS ");
Str = formatter. format (today );
Return str + "." + s1;
}

/********************* File Upload **************** ************/

FormFile file = ef. getFile ();
String Savefilepath = "";
String Savefilename = "";

If (! (File. getFileName (). equals (""))
{
Try {
InputStream stream = file. getInputStream (); // read the file
Savefilepath = request. getRealPath ("/upload"); // the folder in which the file is stored in the current system path.

Savefilename = getNewFilename (file. getFileName ());
Savefilepath = Savefilepath + "\" + Savefilename;

// Save the file name to the database
Empl. setRemark (Savefilename );

OutputStream bos = new FileOutputStream (Savefilepath); // create an output stream for the uploaded file

Int bytesRead = 0;
Byte [] buffer = new byte [10*1024];
While (bytesRead = stream. read (buffer, 0, 10240 ))! =-1 ){
Bos. write (buffer, 0, bytesRead); // write the file to the server's hard disk.
}
Bos. close ();
Stream. close ();
} Catch (Exception e ){
E. printStackTrace ();
}
}

/********************* File Upload **************** ************/

 

<Td> </td>

String content = ds. toGBK (ds. toString (String) request. getParameter ("content ")));

<Object classid = clsid: 22d6f312-b0f6-11d0-94ab-0080c74c7e95 width = 450 height = 400> <param name = showstatusbar value = 1> <param name = filename value = '.. /video/upload/<% = sp %> '> <embed src ='/news/upload/1. wmv '> </embed> </object>

 

Jdbc: oracle: thin: @ 192.168.0.13: 1521: dbstudy

Oracle. jdbc. driver. OracleDriver

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.