如何从程序中退出java应用程序 [英] How to quit a java app from within the program

查看:316
本文介绍了如何从程序中退出java应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用代码退出Java应用程序的最佳方法是什么?

What's the best way to quit a Java application with code?

推荐答案

您可以使用System.exit()为此目的。

You can use System.exit() for this purpose.

根据oracle的Java 8文档:

According to oracle's Java 8 documentation:


public static void exit(int status)

终止当前运行的Java虚拟机。该参数用作状态代码;按照惯例,非零状态代码表示异常终止

Terminates the currently running Java Virtual Machine. The argument serves as a status code; by convention, a nonzero status code indicates abnormal termination.

此方法在类Runtime中调用exit方法。此方法永远不会正常返回。

This method calls the exit method in class Runtime. This method never returns normally.

调用 System.exit(n)实际上等同于调用:

The call System.exit(n) is effectively equivalent to the call:

Runtime.getRuntime()。exit(n)

这篇关于如何从程序中退出java应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆