Terminate a Java application : System « Development Class « Java






Terminate a Java application

       
import java.io.File;

public class Main {
  public static void main(String[] args) {
    File file = new File("config.xml");

    int errCode = 0;
    if (!file.exists()) {
      errCode = 1;
    } else {
      errCode = 0;
    }

    // When the error code is not zero go terminate
    if (errCode > 0) {
      System.exit(errCode);
    }
  }
} 

   
    
    
    
    
    
    
  








Related examples in the same category

1.Exiting a Java program
2.Terminate virtual machine using System class
3.Run object finalization using System class
4.Run the garbage collector using System class
5.Reading Text from Standard Input
6.Get file separator using System class
7.System Level Utils
8.Utilities relating to the version of Java in use at runtime
9.System IO Redirect
10.Helpers for java.lang.System
11.Methods to aid classes recover from OutOfMemoryErrors by denying or reducing service rather than a complete shutdown of the JVM.
12.A window that displays the bytes sent to System.out and System.err
13.This program runs the Sieve of Erathostenes benchmarkThis program runs the Sieve of Erathostenes benchmark