System类

System系统类的一些属性及方法:

 

import java.util.Iterator;
import java.util.Properties;
import java.util.Set;

public class SystemDemo {

	private static final String FILE_SEPARATOR = System.getProperty("file.separator");
	//file.separator文件分割符
	private static final String LINE_SEPARATOR = System.getProperty("line.separator");
	//line.separator换行符
	
	public static void main(String[] args) {
		
		/*
		 * System:全是静态属性和行为。
		 * 属性:
		 * out:标准输出流,默认对应设备显示器
		 * in:标准输入流,默认的设备键盘
		 * 
		 */
		
//		long time = System.currentTimeMillis();
//		System.out.println(time);//毫秒值
		
		/*
		 * System  getProperties();
		 * Properties继承自HashTable是一个双列集合
		 * getProperties()获取键值(都是字符串)
		 */
		Properties prop = System.getProperties();
		
		Set<String> set = prop.stringPropertyNames();//Properties的方法stringPropertyNames()取出键
		
		/*for(String key: set){
			String value = prop.getProperty(key);//getProperty()获取值
			System.out.println(key+"....."+value);
		}*/
		
		System.out.println(prop.getProperty("os.name"));
		
		//开发
		//文件分隔符,不同系统的分隔符不同,增强程序的可移植性
		System.out.println("c:"+FILE_SEPARATOR+"abc");
		//换行符
		System.out.println("hello"+LINE_SEPARATOR+"world");
		
		//c:\\abc.txt;d:\\qq.txt  路径分隔符
		//同上System.getProperty("path.separator");
	}
}

获取到的一些系统属性:

 

java.runtime.name.....Java(TM) SE Runtime Environment
sun.boot.library.path.....C:\Program Files (x86)\Java\jdk1.8.0_66\jre\bin
java.vm.version.....25.66-b18
java.vm.vendor.....Oracle Corporation
java.vendor.url.....http://java.oracle.com/
path.separator.....;
java.vm.name.....Java HotSpot(TM) Client VM
file.encoding.pkg.....sun.io
user.script.....
user.country.....CN
sun.java.launcher.....SUN_STANDARD
sun.os.patch.level.....
java.vm.specification.name.....Java Virtual Machine Specification
user.dir.....D:\EclipseWorkspace\workspaceForJAVA\JAVAproject
java.runtime.version.....1.8.0_66-b18
java.awt.graphicsenv.....sun.awt.Win32GraphicsEnvironment
java.endorsed.dirs.....C:\Program Files (x86)\Java\jdk1.8.0_66\jre\lib\endorsed
os.arch.....x86
java.io.tmpdir.....C:\Users\dell\AppData\Local\Temp\
line.separator.....


java.vm.specification.vendor.....Oracle Corporation
user.variant.....
os.name.....Windows 8.1
sun.jnu.encoding.....GBK
java.library.path.....C:\Program Files (x86)\Java\jdk1.8.0_66\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:/Program Files (x86)/Java/jdk1.8.0_66/bin/../jre/bin/client;C:/Program Files (x86)/Java/jdk1.8.0_66/bin/../jre/bin;C:/Program Files (x86)/Java/jdk1.8.0_66/bin/../jre/lib/i386;C:\Program Files\MySQL\MySQL Server 5.5\bin;C:\Program Files (x86)\Java\jdk1.8.0_66\bin;C:\Program Files (x86)\Android\android-sdk\tools;;D:\应用软件\Eclipse\eclipse;;.
java.specification.name.....Java Platform API Specification
java.class.version.....52.0
sun.management.compiler.....HotSpot Client Compiler
os.version.....6.3
user.home.....C:\Users\dell
user.timezone.....
java.awt.printerjob.....sun.awt.windows.WPrinterJob
file.encoding.....GBK
java.specification.version.....1.8
user.name.....dell
java.class.path.....D:\EclipseWorkspace\workspaceForJAVA\JAVAproject\bin
java.vm.specification.version.....1.8
sun.arch.data.model.....32
java.home.....C:\Program Files (x86)\Java\jdk1.8.0_66\jre
sun.java.command.....cn.qujianlei.api.SystemDemo
java.specification.vendor.....Oracle Corporation
user.language.....zh
awt.toolkit.....sun.awt.windows.WToolkit
java.vm.info.....mixed mode, sharing
java.version.....1.8.0_66
java.ext.dirs.....C:\Program Files (x86)\Java\jdk1.8.0_66\jre\lib\ext;C:\Windows\Sun\Java\lib\ext
sun.boot.class.path.....C:\Program Files (x86)\Java\jdk1.8.0_66\jre\lib\resources.jar;C:\Program Files (x86)\Java\jdk1.8.0_66\jre\lib\rt.jar;C:\Program Files (x86)\Java\jdk1.8.0_66\jre\lib\sunrsasign.jar;C:\Program Files (x86)\Java\jdk1.8.0_66\jre\lib\jsse.jar;C:\Program Files (x86)\Java\jdk1.8.0_66\jre\lib\jce.jar;C:\Program Files (x86)\Java\jdk1.8.0_66\jre\lib\charsets.jar;C:\Program Files (x86)\Java\jdk1.8.0_66\jre\lib\jfr.jar;C:\Program Files (x86)\Java\jdk1.8.0_66\jre\classes
java.vendor.....Oracle Corporation
file.separator.....\
java.vendor.url.bug.....http://bugreport.sun.com/bugreport/
sun.cpu.endian.....little
sun.io.unicode.encoding.....UnicodeLittle
sun.desktop.....windows
sun.cpu.isalist.....pentium_pro+mmx pentium_pro pentium+mmx pentium i486 i386 i86

 

 

关注我的微信公众号(曲健磊的个人随笔),观看更多精彩内容:


 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值