Example usage for java.lang Exception printStackTrace

List of usage examples for java.lang Exception printStackTrace

Introduction

In this page you can find the example usage for java.lang Exception printStackTrace.

Prototype

public void printStackTrace() 

Source Link

Document

Prints this throwable and its backtrace to the standard error stream.

Usage

From source file:MainClass.java

public static void main(String args[]) {

    try {//from   www  . j av a2  s  . c  om

        File oldFile = new File(args[0]);

        File newFile = new File(args[1]);

        boolean result = oldFile.renameTo(newFile);

        System.out.println(result);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:Main.java

public static void main(String[] args) {
    String s = "Hello";
    try {/* ww w .  j a va 2s  .  c  om*/

        PrintWriter pw = new PrintWriter(System.out);

        // write strings
        pw.write(s);
        pw.write(" World");

        // flush the writer
        pw.flush();

    } catch (Exception ex) {
        ex.printStackTrace();
    }
}

From source file:Main.java

public static void main(String args[]) {
    try {//  w w  w. j  a v  a  2s  .  c o  m

        InetAddress ia = InetAddress.getByName("www.java2s.com");

        DatagramSocket ds = new DatagramSocket(8080, ia);

        byte buffer[] = "hello".getBytes();
        DatagramPacket dp = new DatagramPacket(buffer, buffer.length, ia, 80);
        ds.connect(InetSocketAddress.createUnresolved("google.com", 8080));
        ds.send(dp);
        ds.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:Main.java

public static void main(String[] args) {
    boolean bool = false;
    try {/*from   w  w  w . j  a  v a  2s.  com*/

        PrintWriter pw = new PrintWriter(System.out);

        // print boolean
        pw.println(bool);
        pw.println(true);

        // flush the writer
        pw.flush();

    } catch (Exception ex) {
        ex.printStackTrace();
    }
}

From source file:Main.java

public static void main(String args[]) {
    try {//from w  w  w.ja  v a  2s  .  c  o  m

        InetAddress ia = InetAddress.getByName("www.java2s.com");

        DatagramSocket ds = new DatagramSocket();

        byte buffer[] = "hello".getBytes();
        DatagramPacket dp = new DatagramPacket(buffer, buffer.length, ia, 80);
        ds.bind(InetSocketAddress.createUnresolved("google.com", 8080));
        ds.send(dp);
        ds.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:Main.java

public static void main(String[] args) {
    String s = "tutorial from java2s.com";
    try {/* www. ja  v a2s .c o m*/

        PrintWriter pw = new PrintWriter(System.out);

        // format text with default locale
        // %s indicates a string will be placed there, which is s
        pw.format("This is a %s program", s);

        // flush the writer
        pw.flush();

    } catch (Exception ex) {
        ex.printStackTrace();
    }
}

From source file:ExampleBarcodePDF417.java

public static void main(String[] args) {
    try {/* www.  j ava2  s . co m*/
        BarcodePDF417 pdf417 = new BarcodePDF417();
        pdf417.setText("www.java2s.com has some demo for PDF");
        Document document = new Document(PageSize.A4, 50, 50, 50, 50);
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("ExampleBarcodePDF417.pdf"));
        document.open();
        Image img = pdf417.getImage();
        img.scalePercent(50, 50 * pdf417.getYHeight());
        document.add(img);
        document.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:Main.java

public static void main(String[] args) {
    String s = "tutorial from java2s.com";
    try {//from   ww w .j a  v  a  2 s  . com

        // create a new stream at specified file
        PrintWriter pw = new PrintWriter(System.out);

        // write the string in the file
        pw.write(s);

        // flush the writer
        pw.flush();

    } catch (Exception ex) {
        ex.printStackTrace();
    }
}

From source file:Main.java

public static void main(String args[]) {
    try {/* w  w w . j a v a  2s .  com*/

        InetAddress ia = InetAddress.getByName("www.java2s.com");

        DatagramSocket ds = new DatagramSocket();

        byte buffer[] = "hello".getBytes();
        DatagramPacket dp = new DatagramPacket(buffer, buffer.length, ia, 80);
        ds.connect(InetSocketAddress.createUnresolved("google.com", 80));
        ds.send(dp);
        ds.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:Main.java

public static void main(String args[]) {
    try {// w  ww .j  av a 2  s  .c  om

        InetAddress ia = InetAddress.getByName("www.java2s.com");

        DatagramSocket ds = new DatagramSocket();

        byte buffer[] = "hello".getBytes();
        DatagramPacket dp = new DatagramPacket(buffer, buffer.length, ia, 80);
        ds.connect(InetSocketAddress.createUnresolved("google.com", 8080));
        ds.send(dp);
        ds.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
}