List of usage examples for java.lang System exit
public static void exit(int status)
From source file:GetIP.java
public static void main(String[] args) { InetAddress address = null;// w w w . j a va2s . c o m try { address = InetAddress.getByName("www.java2s.com"); } catch (UnknownHostException e) { System.exit(2); } System.out.println(address.getHostName() + "=" + address.getHostAddress()); System.exit(0); }
From source file:PasswordPromptingDemo.java
public static void main(String[] args) { Console console = System.console(); if (console == null) { System.out.println("Console is not available"); System.exit(1); }/* w w w .java 2 s . c o m*/ char[] password = "mustang".toCharArray(); char[] passwordEntered = console.readPassword("Enter password: "); if (Arrays.equals(password, passwordEntered)) { System.out.println("\n Access granted \n"); Arrays.fill(password, ' '); Arrays.fill(passwordEntered, ' '); System.out.println("OK ..."); } else { System.out.println("Access denied"); System.exit(1); } }
From source file:OptionDialog.java
public static void main(String argv[]) { if (JOptionPane.showConfirmDialog(new JFrame(), "Do you want to quit this application ?", "Title", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) System.exit(0); }
From source file:MailExample.java
public static void main(String args[]) throws Exception { if (args.length != 3) { System.err.println("Usage: java MailExample host from to"); System.exit(-1); }//from ww w . ja v a2 s . com String host = args[0]; String from = args[1]; String to = args[2]; // Get system properties Properties props = System.getProperties(); // Setup mail server props.put("mail.smtp.host", host); // Get session Session session = Session.getDefaultInstance(props, null); // Define message MimeMessage message = new MimeMessage(session); message.setFrom(new InternetAddress(from)); message.addRecipient(Message.RecipientType.TO, new InternetAddress(to)); message.setSubject("The Subject"); message.setText("The Message"); // Send message Transport.send(message); }
From source file:Rename.java
public static void main(String[] args) throws Exception { String initialContextString = "/"; if (args.length < 2) { System.out.println("Useage: java Rename filename1 filename2"); System.exit(-1); }/*www . j a v a2 s .c o m*/ Hashtable env = new Hashtable(); env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.fscontext.RefFSContextFactory"); env.put(Context.PROVIDER_URL, "file:" + initialContextString); Context initCtx = new InitialContext(env); System.out.println("Renaming " + args[0] + " to " + args[1]); initCtx.rename(args[0], args[1]); }
From source file:MainClass.java
public static void main(String[] args) { Timer t = new Timer(1000, new Ticker()); t.start();// w ww . ja v a 2s .co m JOptionPane.showMessageDialog(null, "Click OK to exit program"); System.exit(0); }
From source file:Copy.java
public static void main(String[] args) { FileChannel in = null;//from ww w . j av a 2 s .co m FileChannel out = null; if (args.length < 2) { System.out.println("Usage: java Copy <from> <to>"); System.exit(1); } try { in = new FileInputStream(args[0]).getChannel(); out = new FileOutputStream(args[1]).getChannel(); out.transferFrom(in, 0L, (int) in.size()); } catch (Exception e) { e.printStackTrace(); } }
From source file:PrintFile.java
public static void main(String args[]) throws Exception { if (args.length != 2) { System.err.println("usage : java PrintFile port file"); System.err.println("sample: java PrintFile LPT1 sample.prn"); System.exit(-1); }/* ww w. j a va 2 s .com*/ String portname = args[0]; String filename = args[1]; // Get port CommPortIdentifier portId = CommPortIdentifier.getPortIdentifier(portname); // Open port // Requires owner name and timeout CommPort port = portId.open("Java Printing", 30000); // Setup reading from file FileInputStream fis = new FileInputStream(filename); BufferedInputStream bis = new BufferedInputStream(fis); // Setup output OutputStream os = port.getOutputStream(); BufferedOutputStream bos = new BufferedOutputStream(os); int c; while ((c = bis.read()) != -1) { bos.write(c); } // Close bos.close(); bis.close(); port.close(); }
From source file:Main.java
public static void main(String[] args) { File file = new File("config.xml"); int errCode = 0; if (!file.exists()) { errCode = 1;/*from w w w . j a va 2 s.c o m*/ } else { errCode = 0; } // When the error code is not zero go terminate if (errCode > 0) { System.exit(errCode); } }
From source file:Delete.java
public static void main(String[] args) throws Exception { String initalContextString = "/tmp/marketing/reports"; if (args.length < 1) { System.out.println("Usage: java Delete filename"); System.exit(-1); }//www. ja v a 2 s.co m System.out.println("This program assumes the context is " + initalContextString); Hashtable env = new Hashtable(); env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.fscontext.RefFSContextFactory"); env.put(Context.PROVIDER_URL, "file:" + initalContextString); Context initCtx = new InitialContext(env); System.out.println("Attempting to unbind " + args[0]); initCtx.unbind(args[0]); System.out.println("Done."); }