This is the Upload class method:
public class Upload {
public static String upload (formfile formfile,string dirpath,int port) {
String savepath= "";
String ip= "";
try{
String filename = formfile.getfilename (). Trim (); Filename
if (! "". equals (filename)) {
InputStream ins = Formfile.getinputstream ();
String currentpath=dirpath+ File.separatorchar + filename; File Save path
OutputStream OS = new FileOutputStream (Currentpath);
int bytesread = 0;
byte[] buffer = new byte[8192];
while ((bytesread = ins.read (buffer, 0, 8192))!=-1) {
Os.write (buffer, 0, bytesread);
}
Boolean Iswindows=iswindowsos (); Determine if the Windows system
if (iswindows) {
InetAddress Address=inetaddress.getlocalhost ();
Ip=address.gethostaddress (); Get IP Address
SYSTEM.OUT.PRINTLN ("Windows IP Address:" +IP);
}
else{//If it is a Linux system
Ip=tools.getlinuxip ();
SYSTEM.OUT.PRINTLN ("Linux IP Address:" +IP);
}
Savepath= "http://" +ip+ ":" +port+ "/channelproject/upload/"; Save to the address of the database, upload the picture to the server side
Savepath+=filename;
Os.close ();
Ins.close ();
}
}
catch (Exception e) {
E.printstacktrace ();
System.out.println ("Upload error!!");
}
return savepath;
}
/*
* @return True---is the Windows operating system
*/
public static Boolean Iswindowsos () {
Boolean Iswindowsos = false;
String osname = System.getproperty ("Os.name");
if (Osname.tolowercase (). IndexOf ("Windows") >-1) {
Iswindowsos = true;
}
return Iswindowsos;
}
}