Java Judge is window System or Linux system, and get its IP address and file upload __linux

Source: Internet
Author: User
Tags file upload get ip

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;
}
}

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.