if (file! = null) {
try {
InputStream in = new FileInputStream (file);
Long Size=long.parselong (in.available () + "");
String realname = File.getname ();
String img= (realname.substring (Realname.lastindexof (".") +1,realname.length ()). toLowerCase ();
String dir = servletactioncontext.getrequest (). Getrealpath ("/goodsimg");
if (size<5000000) {
File UploadFile = new file ("C:\\users\\administrator\\desktop\\img", picname+ ". jpg");
OutputStream out = new FileOutputStream (uploadfile);
byte[] buffer = new byte[1024 * 1024];
int lenght;
while ((lenght = in.read (buffer)) > 0) {
Out.write (buffer, 0, lenght);
}
In.close ();
Out.close ();
}
} catch (Exception e) {
throw new RuntimeException (e);
}
}
This article is from the "DSLZC" blog, make sure to keep this source http://dslzc921029.blog.51cto.com/10187165/1657104
Upload Image Java