天天看點

javaSE-常用類-System

public class SystemDemo {

	private static final String LINE_SEPARATOR = System.getProperty("line.separator");

	public static void main(String[] args) {

		/*
		 * System:
		 * 全是靜态的成員,不能執行個體化。
		 * 
		 */
		//示範System。擷取目前時間。
		
		long time= System.currentTimeMillis();
		System.out.println(time);//1364114590000
		
		
		Properties prop = System.getProperties();
		//擷取系統的屬性資訊。
		for (String key : prop.stringPropertyNames()) {
			System.err.println(key+"="+prop.getProperty(key));
		}
		/*
		 * Set<String> keySet = prop.stringPropertyNames();
		 * 
		 * Iterator<String> it = keySet.iterator(); while(it.hasNext()){ String
		 * key = it.next(); String value = prop.getProperty(key);
		 * 
		 * System.out.println(key+"::"+value); }
		 */
		
		//通過指定鍵擷取值。
//		String osName = System.getProperty("os.name");
//		System.out.println(osName);
		
		//通過System.getProperty("line.separator")就可以實作在任何作業系統,都可以換行。
		//因為System.getProperty("line.separator")是擷取與系統平台有關的行分隔符。
		System.out.println("hello"+LINE_SEPARATOR+"world");
	
	}
}