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:AuthorizedFileWriter.java

public static void main(String[] args) {
    System.setSecurityManager(new SecurityManager());
    String file = "authorized.txt";
    String fileBody = "test";
    try {// ww  w .ja  va  2s .  com
        FileWriter fileWriter = new FileWriter(file);
        fileWriter.write(fileBody);
        fileWriter.close();
        System.exit(0);
    } catch (IOException ioException) {
        ioException.printStackTrace();
        System.exit(1);
    }
}

From source file:Main.java

public static void main(String[] args) {
    try {//  ww  w .j a  v  a 2s .  c  om
        float f = 1234.56f;

        RandomAccessFile raf = new RandomAccessFile("c:/test.txt", "rw");

        // write something in the file
        raf.writeFloat(987.654f);

        // set the file pointer at 0 position
        raf.seek(0);

        // read float
        System.out.println(raf.readFloat());

        // set the file pointer at 0 position
        raf.seek(0);

        // write a float
        raf.writeFloat(f);

        // set the file pointer at 0 position
        raf.seek(0);

        // read float
        System.out.println(raf.readFloat());
        raf.close();
    } catch (IOException ex) {
        ex.printStackTrace();
    }

}

From source file:Main.java

public static void main(String[] args) {
    try {//from ww  w.  jav a  2 s  .c  o m
        int i = 123;

        RandomAccessFile raf = new RandomAccessFile("c:/test.txt", "rw");

        // write something in the file
        raf.writeInt(123);

        // set the file pointer at 0 position
        raf.seek(0);

        // print the int
        System.out.println(raf.readInt());

        // set the file pointer at 0 position
        raf.seek(0);

        // write something in the file
        raf.writeInt(i);

        // set the file pointer at 0 position
        raf.seek(0);

        // print the int
        System.out.println(raf.readInt());
        raf.close();
    } catch (IOException ex) {
        ex.printStackTrace();
    }

}

From source file:Main.java

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

        RandomAccessFile raf = new RandomAccessFile("c:/test.txt", "rw");

        // write something in the file
        raf.writeShort(s);

        // set the file pointer at 0 position
        raf.seek(0);

        // print the short
        System.out.println(raf.readShort());

        // set the file pointer at 0 position
        raf.seek(0);

        // write something in the file
        raf.writeShort(134);

        // set the file pointer at 0 position
        raf.seek(0);

        // print the short
        System.out.println(raf.readShort());
        raf.close();
    } catch (IOException 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

        RandomAccessFile raf = new RandomAccessFile("c:/test.txt", "rw");

        raf.writeUTF("Hello World from java2s.com");

        // set the file pointer at 0 position
        raf.seek(0);

        // print the string
        System.out.println(raf.readUTF());

        // set the file pointer at 0 position
        raf.seek(0);

        // attempt to skip 10 bytes
        System.out.println(raf.skipBytes(10));

        System.out.println(raf.readLine());

        // set the file pointer to position 8
        raf.seek(8);

        // attempt to skip 10 more bytes
        System.out.println(raf.skipBytes(10));
        raf.close();
    } catch (IOException ex) {
        ex.printStackTrace();
    }

}

From source file:PrintImage.java

static public void main(String args[]) throws Exception {
    try {/*from w  w  w  .ja  v a 2 s .  co m*/
        PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
        pras.add(new Copies(1));

        PrintService pss[] = PrintServiceLookup.lookupPrintServices(DocFlavor.INPUT_STREAM.GIF, pras);

        if (pss.length == 0)
            throw new RuntimeException("No printer services available.");

        PrintService ps = pss[0];
        System.out.println("Printing to " + ps);

        DocPrintJob job = ps.createPrintJob();

        FileInputStream fin = new FileInputStream("YOurImageFileName.PNG");
        Doc doc = new SimpleDoc(fin, DocFlavor.INPUT_STREAM.GIF, null);

        job.print(doc, pras);

        fin.close();
    } catch (IOException ie) {
        ie.printStackTrace();
    } catch (PrintException pe) {
        pe.printStackTrace();
    }
}

From source file:Main.java

public static void main(String[] args) {

    try {//w  w  w.j  a  v  a  2s.  c om
        DTD d1 = DTD.getDTD("html");
        for (int i = 0; i < 14; i++) {
            System.out.println(d1.getElement(i).getName());
        }

    } catch (IOException e) {
        System.err.println(e);
        e.printStackTrace();
    }

}

From source file:com.igalia.metamail.Main.java

public static void main(String[] args) {
    try {//ww  w. j  av  a 2 s  .  c  o m
        String filename = "../enron-importer/data/maildir/lay-k/sent/1.";
        byte[] body = FileUtils.readFileToByteArray(new File(filename));
        InputStream input = new ByteArrayInputStream(body);
        Session s = Session.getDefaultInstance(new Properties());

        MailRecord mail = MailRecord.create(s, input);
        System.out.println("To: " + mail.getTo());
    } catch (IOException e) {
        e.printStackTrace();
    } catch (MessagingException e) {
        e.printStackTrace();
    }
}

From source file:json.WriteToFile.java

public static void main(String[] args) {
    JSONObject countryObj = new JSONObject();
    countryObj.put("Name", "Kenya");
    countryObj.put("Population", new Integer(430000000));
    JSONArray listOfCounties = new JSONArray();
    listOfCounties.add("Nairobi");
    listOfCounties.add("Kiambu");
    listOfCounties.add("Murang'a");

    countryObj.put("Counties", listOfCounties);
    try {/*from   w  w w  .ja  v  a 2 s . co  m*/
        //writing to file
        File file = new File("/home/mars/Desktop/JsonExample1.json");
        file.createNewFile();
        FileWriter fw = new FileWriter(file);
        System.out.println("Writing JSON object to file");
        System.out.println("---------------------------");
        System.out.println(countryObj);

        fw.write(countryObj + "");
        fw.flush();
        fw.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:FindDirectories.java

public static void main(String[] args) {
    // if no arguments provided, start at the parent directory
    if (args.length == 0)
        args = new String[] { ".." };

    try {//from  www  .  j a  va2 s.c o  m
        File pathName = new File(args[0]);
        String[] fileNames = pathName.list();

        // enumerate all files in the directory
        for (int i = 0; i < fileNames.length; i++) {
            File f = new File(pathName.getPath(), fileNames[i]);

            // if the file is again a directory, call the main method recursively
            if (f.isDirectory()) {
                System.out.println(f.getCanonicalPath());
                main(new String[] { f.getPath() });
            }
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
}