java判断系统
❶ java判断当前运行系统是否是windows系统
public static boolean isWindows() {
return System.getProperties().getProperty("os.name").toUpperCase().indexOf("WINDOWS") != -1;
}
❷ JAVA判断当前操作系统环境是xp还是linux
JAVA判断当前操作系统环境是xp还是linux可用os.name来实现。
代码如下:
publicclassA
{
publicstaticvoidmain(String[]args)
{
System.out.println(System.getProperty("os.name"));
}
}
❸ java中如何在类中判断客户端操作系统是32位的还是64位的操作系统
这个无法获取。。你只能根据请求的头去分析,一般是分析请求头中的UA,如下:
String userAgent = request.getHeader("user-agent");
/**
* 获取客户端操作系统信息,目前只匹配Win 7、WinXP、Win2003、Win2000、MAC、WinNT、Linux、Mac68k、Win9x
* @param userAgent request.getHeader("user-agent")的返回值
* @return
*/
public static String getClientOS(String userAgent)
{
String cos = "unknow os";
Pattern p = Pattern.compile(".*(Windows NT 6\\.1).*");
Matcher m = p.matcher(userAgent);
if(m.find())
{
cos = "Win 7";
return cos;
}
p = Pattern.compile(".*(Windows NT 5\\.1|Windows XP).*");
m = p.matcher(userAgent);
if(m.find())
{
cos = "WinXP";
return cos;
}
p = Pattern.compile(".*(Windows NT 5\\.2).*");
m = p.matcher(userAgent);
if(m.find())
{
cos = "Win2003";
return cos;
}
p = Pattern.compile(".*(Win2000|Windows 2000|Windows NT 5\\.0).*");
m = p.matcher(userAgent);
if(m.find())
{
cos = "Win2000";
return cos;
}
p = Pattern.compile(".*(Mac|apple|MacOS8).*");
m = p.matcher(userAgent);
if(m.find())
{
cos = "MAC";
return cos;
}
p = Pattern.compile(".*(WinNT|Windows NT).*");
m = p.matcher(userAgent);
if(m.find())
{
cos = "WinNT";
return cos;
}
p = Pattern.compile(".*Linux.*");
m = p.matcher(userAgent);
if(m.find())
{
cos = "Linux";
return cos;
}
p = Pattern.compile(".*(68k|68000).*");
m = p.matcher(userAgent);
if(m.find())
{
cos = "Mac68k";
return cos;
}
p = Pattern.compile(".*(9x 4.90|Win9(5|8)|Windows 9(5|8)|95/NT|Win32|32bit).*");
m = p.matcher(userAgent);
if(m.find())
{
cos = "Win9x";
return cos;
}
return cos;
}
❹ java判断是window系统还是Linux系统,并获取其IP地址及文件上传
判断系统类型
System.getPriperties //好像是这个函数,查查 DOC文档就知道了。
获得一个类似 Map的数据结构,里面包含了当前各种属性数据
比如系统类型,版本,临时文件目录,当前登录用户名(操作系统的登录用户)
用户的临时目录所在位置等等。
获取当前机器IP地址,要用java.net.*下面的类完成。
❺ java 如何判断操作系统是Linux还是Windows
Java 判断操作系统是linux还是windows,主要是使用system这个类,这个类型提供了获取java版本、安装目录、操作系统等等信息,代码如下:
System.out.println("===========操作系统是:"+System.getProperties().getProperty("os.name"));
System.out.println("===========文件的分隔符为file.separator:"+System.getProperties().getProperty("file.separator"));
System类
public staticPropertiesgetProperties()
将getProperty(String)方法使用的当前系统属性集合作为Properties对象返回
键 相关值的描述
java.version Java 运行时环境版本
java.vendor Java 运行时环境供应商
java.vendor.url Java 供应商的 URL
java.home Java 安装目录
❻ java 如何判断操作系统的类型
Properties prop = System.getProperties();
String os = prop.getProperty("os.name");
System.out.println(os);
os.startWith("win") || os.startWith("Win") == windows操作系统
❼ 请教Java 如何判断操作系统是32位还是64位
Java 判断操作系统的位数得通过 JNI。
经常有人说使用 System.getProperty("os.arch"),事实上这获得的是 CPU 的架构,而现在 CPU 一般都是 64 位的架构。
如果是 SUN/Oracle 的 JDK,可以使用 System.getProperty("sun.arch.data.model"); 来获得 JVM 是 32 位的还是 64 位的。
❽ java 根据ip判断操作系统
根据ip没办法判断操作系统,只能获取hostname。
但是可以通过ping ip地址的TTL来判断操作系统。
TTL=128,一般是WINNT/2K/XP。
TTL=32,一般是WIN95/98/ME。
TTL=256,一般是UNIX。
TTL=64,一般是LINUX。
但有可能被欺骗。
❾ java怎么样判断当前系统时间
通过new Date获取当前的日期与时间
public static void main(String[] args){
Date now = new Date(); //获取当前时间
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");//格式化当前日期时间,显示如2015/06/27 14:22:22
}
❿ 怎样用java代码判断当前系统是64位还是32位的
public static void getSystemProperties(){
Properties props=System.getProperties();
Iterator iter=props.keySet().iterator();
while(iter.hasNext())
{
String key=(String)iter.next();
if(key.equals("sun.arch.data.model"))
System.out.println( props.get(key));
}
}
sun.arch.data.model属性是指的是cpu的位数