String cmd = "rundll32 url.dll,FileProtocolHandler http://www.apple.com";
Runtime.getRuntime().exec(cmd);
private static final String WIN_ID = "Windows";

public static boolean isWindowsPlatform() ...{
String os = System.getProperty("os.name");
if ( os != null && os.startsWith(WIN_ID))
return true;
else
return false;
}
private static final String MAC_ID = "Mac";

public static boolean isMacPlatform() ...{
String os = System.getProperty("os.name");
if ( os != null && os.startsWith(MAC_ID))
return true;
else
return false;
}
public static void openMacURL(String url) ...{
try...{
Class MRJFileUtils = Class.forName("com.apple.mrj.MRJFileUtils");
Method openMethod = MRJFileUtils.getDeclaredMethod("openURL", new Class[] ...{String.class});
openMethod.invoke(MRJFileUtils,new Object[]...{formatString(url)});
} catch(Exception e) ...{
e.printStackTrace();
}
}
public static String formatString(String str) ...{
String retString="";
String protocol = "";
String host = "";
String path = "";

try ...{
java.net.URL url = new java.net.URL(str);
protocol = url.getProtocol();
host = url.getHost();
path = url.getPath();
} catch (MalformedURLException ex) ...{
path = str;
}

for(int i = 0; i < path.length(); i++) ...{
if(path.charAt(i) == ' ') ...{
retString += "%20";
} else if(path.charAt(i) == '.') ...{
retString += "%2E";
} else ...{
retString += path.substring(i, i + 1);
}
}

if (!protocol.equals("")) ...{
retString = protocol + "://" + host + retString;
} else ...{
retString = host + retString;
}
return retString ;
}
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/10294527/viewspace-122995/ ,如需转载,请注明出处,否则将追究法律责任。