(その他)Systemクラスの一般的な方法

1684 ワード


Systemクラスの一般的な方法
 
package com.gc.system;

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

public class Demo {
	public static void main(String[] args) {
		copyArray();
		getTimeMills();
		setSystemProperty();
		clearSystemProperty();
		getSystemProperties();
		getSystemLineSeparator();
	}

	/**
	 *  
	 */
	private static void getSystemLineSeparator() {
		String lineSeparator = System.lineSeparator();
		System.out.print("first"+lineSeparator+"second");
	}
	
	/**
	 *  
	 */
	private static void clearSystemProperty() {
		System.clearProperty("xxx");
	}
	
	/**
	 *  
	 */
	private static void setSystemProperty() {
		System.setProperty("xxx", "yyy");
	}
	
	/**
	 *  
	 */
	private static void getSystemProperties() {
		Properties prop = System.getProperties();
		Set<String> names = prop.stringPropertyNames();
		for(String key : names)
			System.out.println(key+":"+prop.getProperty(key));
	}
	
	/**
	 *  
	 */
	private static void getTimeMills() {
		long timeMills = System.currentTimeMillis();
		System.out.println(timeMills);
	}

	/**
	 *  
	 */
	private static void copyArray() {
		int[] src = {1,2,3,4,5,6,7,8,9};
		int[] dest = new int[5];
		System.arraycopy(src, 2, dest, 0, dest.length);
		for(int i : dest) 
			System.out.println(i);
	}
}