Example usage for java.io IOException printStackTrace

List of usage examples for java.io IOException printStackTrace

Introduction

In this page you can find the example usage for java.io IOException printStackTrace.

Prototype

public void printStackTrace() 

Source Link

Document

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

Usage

From source file:ListFiles.java

public static void main(String[] args) {
    try {/*from ww w  .  j  av  a2  s  .c o  m*/
        Path path = Paths.get("/home");
        ListFiles listFiles = new ListFiles();
        Files.walkFileTree(path, listFiles);
    } catch (IOException ex) {
        ex.printStackTrace();
    }
}

From source file:WriteImageType.java

static public void main(String args[]) throws Exception {
    try {//from  ww  w  . j ava 2 s. com
        int width = 200, height = 200;

        // TYPE_INT_ARGB specifies the image format: 8-bit RGBA packed
        // into integer pixels
        BufferedImage bi = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);

        Graphics2D ig2 = bi.createGraphics();

        Font font = new Font("TimesRoman", Font.BOLD, 20);
        ig2.setFont(font);
        String message = "www.java2s.com!";
        FontMetrics fontMetrics = ig2.getFontMetrics();
        int stringWidth = fontMetrics.stringWidth(message);
        int stringHeight = fontMetrics.getAscent();
        ig2.setPaint(Color.black);
        ig2.drawString(message, (width - stringWidth) / 2, height / 2 + stringHeight / 4);

        ImageIO.write(bi, "PNG", new File("c:\\yourImageName.PNG"));
        ImageIO.write(bi, "JPEG", new File("c:\\yourImageName.JPG"));
        ImageIO.write(bi, "gif", new File("c:\\yourImageName.GIF"));
        ImageIO.write(bi, "BMP", new File("c:\\yourImageName.BMP"));

    } catch (IOException ie) {
        ie.printStackTrace();
    }

}

From source file:org.jfree.chart.demo.SparklineDemo1.java

public static void main(String args[]) {
    XYSeries xyseries = new XYSeries("Series 1");
    xyseries.add(1.0D, 1.0D);//from  w  w w  . j a  v a  2  s .co  m
    xyseries.add(2D, 3D);
    xyseries.add(3D, 2D);
    xyseries.add(4D, 4D);
    XYSeriesCollection xyseriescollection = new XYSeriesCollection();
    xyseriescollection.addSeries(xyseries);
    JFreeChart jfreechart = ChartFactory.createXYLineChart(null, "X", "Y", xyseriescollection,
            PlotOrientation.VERTICAL, false, false, false);
    XYPlot xyplot = (XYPlot) jfreechart.getPlot();
    xyplot.setInsets(RectangleInsets.ZERO_INSETS);
    xyplot.setDomainGridlinesVisible(false);
    xyplot.setRangeGridlinesVisible(false);
    xyplot.setOutlinePaint(null);
    xyplot.getDomainAxis().setVisible(false);
    xyplot.getRangeAxis().setVisible(false);
    try {
        ChartUtilities.saveChartAsPNG(new File("Sparky.png"), jfreechart, 100, 20);
    } catch (IOException ioexception) {
        ioexception.printStackTrace();
    }
}

From source file:Employee.java

public static void main(String[] args) {
    Employee e = new Employee();
    e.name = "A";
    e.address = "B";
    e.SSN = 11111;//from  w ww .ja  v a 2  s  .  c  o m
    e.number = 101;
    try {
        FileOutputStream fileOut = new FileOutputStream("employee.ser");
        ObjectOutputStream out = new ObjectOutputStream(fileOut);
        out.writeObject(e);
        out.close();
        fileOut.close();
    } catch (IOException i) {
        i.printStackTrace();
    }
}

From source file:MainClass.java

public static void main(String[] args) {
    int port = Integer.parseInt(args[0]);

    try {// www .j a v  a2  s.  c o m
        System.out.println("Locating server socket factory for SSL...");
        SSLServerSocketFactory factory = (SSLServerSocketFactory) SSLServerSocketFactory.getDefault();

        System.out.println("Creating a server socket on port " + port);
        SSLServerSocket serverSocket = (SSLServerSocket) factory.createServerSocket(port);

        String[] suites = serverSocket.getSupportedCipherSuites();
        System.out.println("Support cipher suites are:");
        for (int i = 0; i < suites.length; i++) {
            System.out.println(suites[i]);
        }
        serverSocket.setEnabledCipherSuites(suites);

        System.out.println("Support protocols are:");
        String[] protocols = serverSocket.getSupportedProtocols();
        for (int i = 0; i < protocols.length; i++) {
            System.out.println(protocols[i]);
        }

        System.out.println("Waiting for client...");
        SSLSocket socket = (SSLSocket) serverSocket.accept();

        System.out.println("Starting handshake...");
        socket.startHandshake();

        System.out.println("Just connected to " + socket.getRemoteSocketAddress());
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:com.mysql.servlet.NewClass.java

public static void main(String[] args) {

    JSONObject headerFile = new JSONObject();

    JSONArray listOfAttrs = new JSONArray();
    listOfAttrs.add("id" + "");
    listOfAttrs.add("name" + "");
    listOfAttrs.add("age" + "");
    listOfAttrs.add("salary" + "");
    listOfAttrs.add("grade" + "");

    headerFile.put("Employee", listOfAttrs);

    try {// w w  w  .  j a  v a2s  . c om

        // Writing to a file  
        File file = new File("D:\\Employees.json");
        file.createNewFile();
        FileWriter fileWriter = new FileWriter(file);
        System.out.println("Writing JSON object to file");
        System.out.println("-----------------------");
        System.out.print(headerFile);

        fileWriter.write(headerFile.toJSONString());
        fileWriter.flush();
        fileWriter.close();

    } catch (IOException e) {
        e.printStackTrace();
    }

}

From source file:ftp_server.FileUploadDemo.java

public static void main(String[] args) {
    FTPClient client = new FTPClient();
    FileInputStream fis = null;//from  w  ww. j a  v a2  s.  co  m
    try {
        client.connect("shamalmahesh.net78.net");
        client.login("a9959679", "9P3IckDo");
        //
        // Create an InputStream of the file to be uploaded
        //
        String filename = "hello.txt";
        fis = new FileInputStream(filename);
        //
        // Store file to server
        //
        client.storeFile(filename, fis);
        client.logout();
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        try {
            if (fis != null) {
                fis.close();
            }
            client.disconnect();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

From source file:MainClass.java

public static void main(String[] a) {
    FileWriter writer;/*from www  . j  av a2s. c  o  m*/
    try {
        writer = new FileWriter("myFile.txt");
        char c = 'A';
        writer.write(c);
        writer.close();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

}

From source file:Employee.java

public static void main(String[] args) {
    Employee e = null;/*from  www  . ja va 2s.com*/
    try {
        FileInputStream fileIn = new FileInputStream("employee.ser");
        ObjectInputStream in = new ObjectInputStream(fileIn);
        e = (Employee) in.readObject();
        in.close();
        fileIn.close();
    } catch (IOException i) {
        i.printStackTrace();
        return;
    } catch (ClassNotFoundException c) {
        System.out.println("Employee class not found");
        c.printStackTrace();
        return;
    }
    System.out.println("Name: " + e.name);
    System.out.println("Address: " + e.address);
    System.out.println("SSN: " + e.SSN);
    System.out.println("Number: " + e.number);
}

From source file:cl.almejo.vsim.Main.java

public static void main(String[] args) {
    try {/*from ww w  .j  a va2  s. com*/
        new Main();
    } catch (IOException e) {
        e.printStackTrace();
    }
}