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

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

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

        // write something in the file
        raf.writeUTF("Hello World from java2s.com");

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

        // read byte
        System.out.println(raf.readByte());

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

        // write 0 at the start
        raf.write(0);

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

}

From source file:Main.java

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

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

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

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

        // create an array equal to the length of raf
        byte[] arr = new byte[(int) raf.length()];

        // read the file
        raf.readFully(arr);

        // create a new string based on arr
        String s2 = new String(arr);

        System.out.println(s2);
        raf.close();
    } catch (IOException ex) {
        ex.printStackTrace();
    }

}

From source file:Main.java

public static void main(String[] args) {
    try {//  www . j  ava  2s.co m

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

        // write something in the file
        raf.writeUTF("java2s.com Hello World");

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

        // read and print the contents of the file
        System.out.println(raf.readUTF());

        // print the length of the file
        System.out.println(raf.length());

        // write something more in the file
        raf.writeUTF("This is an example");

        // print the length of the file
        System.out.println(raf.length());
        raf.close();
    } catch (IOException ex) {
        ex.printStackTrace();
    }

}

From source file:Main.java

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

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

        // write something in the file
        raf.writeUTF("Hello World from java2s.com");

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

        // read boolean
        System.out.println(raf.readBoolean());

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

        // write 0 at the start
        raf.write(0);

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

}

From source file:org.vuphone.vandyupon.test.EventRatingRequestTest.java

public static void main(String[] args) {
    HttpClient c = new DefaultHttpClient();
    HttpPost post = new HttpPost("http://localhost:8080/vandyupon/events/");
    post.addHeader("Content-Type", "application/x-www-form-urlencoded");

    String params = "type=eventpost&eventname=Test&starttime=" + System.currentTimeMillis() + "&endtime="
            + (System.currentTimeMillis() + 6000000)
            + "&userid=chris&resp=xml&desc=a%20new%20event&locationlat=36.1437&locationlon=-86.8046";
    post.setEntity(new ByteArrayEntity(params.toString().getBytes()));

    try {/*from   w  w  w  .j  av  a 2 s. co m*/
        HttpResponse resp = c.execute(post);
        resp.getEntity().writeTo(System.out);
    } catch (IOException e) {
        e.printStackTrace();
    }

}

From source file:ReadZip.java

public static void main(String args[]) {
    try {/*ww  w .j  a v  a  2s.c  o  m*/
        ZipFile zf = new ZipFile("ReadZip.zip");
        Enumeration entries = zf.entries();

        BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
        while (entries.hasMoreElements()) {
            ZipEntry ze = (ZipEntry) entries.nextElement();
            System.out.println("Read " + ze.getName() + "?");
            String inputLine = input.readLine();
            if (inputLine.equalsIgnoreCase("yes")) {
                long size = ze.getSize();
                if (size > 0) {
                    System.out.println("Length is " + size);
                    BufferedReader br = new BufferedReader(new InputStreamReader(zf.getInputStream(ze)));
                    String line;
                    while ((line = br.readLine()) != null) {
                        System.out.println(line);
                    }
                    br.close();
                }
            }
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:Main.java

public static void main(String[] args) {

    String s = "from java2s.com";

    StringReader sr = new StringReader(s);

    // create a new PushBack reader based on our string reader
    PushbackReader pr = new PushbackReader(sr, 20);

    try {/*from   w w  w  .ja  va2 s  .  co  m*/
        // read the first five chars
        for (int i = 0; i < 5; i++) {
            char c = (char) pr.read();
            System.out.println(c);
        }
        // unread a character
        pr.unread('F');

        // read the next char, which is the one we unread
        char c = (char) pr.read();

        System.out.println(c);

        pr.close();

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

From source file:Main.java

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

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

        raf.writeChars(s);

        raf.seek(0);

        for (int i = 0; i < 15; i++) {
            System.out.println(raf.readChar());
        }

        raf.seek(0);

        raf.writeChars("This is an example from java2s.com");

        raf.seek(0);

        for (int i = 0; i < 20; i++) {
            System.out.println(raf.readChar());
        }
        raf.close();
    } catch (IOException ex) {
        ex.printStackTrace();
    }

}

From source file:Main.java

public static void main(String[] args) {

    String s = "from java2s.com";

    StringReader sr = new StringReader(s);

    // create a new PushBack reader based on our string reader
    PushbackReader pr = new PushbackReader(sr);

    try {/*from   w  w w  .  j  ava 2s  .  c o  m*/
        // read the first five chars
        for (int i = 0; i < 5; i++) {
            char c = (char) pr.read();
            System.out.println(c);
        }
        // unread a character
        pr.unread('F');

        // read the next char, which is the one we unread
        char c = (char) pr.read();

        System.out.println(c);

        pr.close();

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

From source file:Main.java

public static void main(String[] args) {

    String s = "from java2s.com";

    StringReader sr = new StringReader(s);

    PushbackReader pr = new PushbackReader(sr, 20);

    try {//from   www  . j av  a 2s  .  com
        for (int i = 0; i < 5; i++) {
            char c = (char) pr.read();
            System.out.println(c);
        }

        char cbuf[] = { 'w', 'o', 'r', 'l', 'd' };

        pr.unread(cbuf);

        for (int i = 0; i < 5; i++) {
            char c = (char) pr.read();
            System.out.println(c);
        }

        pr.close();

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