目 录
一、常用属性
1.static final PrintStream err
2.static final InputStream in
3.static final PrintStream out
二、常用方法
1.arraycopy(Object src, int srcPos, Object dest, int destPos, int length)
2.currentTimeMillis()
3.nanoTime()
4. exit(int status)
5.gc()
6.Map getenv()
7.Properties getProperties
8.String getProperty(String key)
一、常用属性
1.static final PrintStream err
尺度错误输出流。
- public class SystemTest {
- public static void main(String[] args) {
- System.err.println("我错了,原谅我吧!");
- try {
- int a = 0, b = 10;
- System.out.println(b / a);
- } catch (ArithmeticException e) {
- System.err.println("除数不能为0!");
- }
- }
- }
复制代码
2.static final InputStream in
尺度输入流。
3.static final PrintStream out
尺度输出流。
二、常用方法
1.arraycopy(Object src, int srcPos, Object dest, int destPos, int length)
实现数组拷贝,实例见
Java基础关键_008_数组。
2.currentTimeMillis()
获取自 1970年01月01日 00:00:00 起,到系统当前时间的总毫秒数,实例见 Java基础关键_013_日期处置惩罚。
3.nanoTime()
获取自 1970年01月01日 00:00:00 起,到系统当前时间的总纳秒数。
- public class SystemTest {
- public static void main(String[] args) {
- System.out.println(System.currentTimeMillis()); // 1740919048308
- System.out.println(System.nanoTime()); // 523454464575300
- }
- }
复制代码 4. exit(int status)
退出假造机。
5.gc()
发起启动垃圾接纳器。
6.Map<String, String> getenv()
获取当前系统的环境变量。
- public class SystemTest {
- public static void main(String[] args) {
- Map<String, String> getenv = System.getenv();
- System.out.println(getenv.get("JAVA_HOME")); // C:\Program Files\Java\jdk-17
- }
- }
复制代码 7.Properties getProperties
获取当前系统的属性。
- public class SystemTest {
- public static void main(String[] args) {
- Properties properties = System.getProperties();
- System.out.println(properties);
- }
- }
复制代码 8.String getProperty(String key)
获取 key 指定的系统属性。
- public class SystemTest {
- public static void main(String[] args) {
- String property = System.getProperty("java.version");
- System.out.println(property); // 17.0.12
- }
- }
复制代码 免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。 |