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 va2 s .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());

        // print current length
        System.out.println(raf.length());

        // set the file length to 30
        raf.setLength(30);

        System.out.println(raf.length());
        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, 20);

    try {/*from  w w  w. j  a v a 2s. c o m*/
        // check if the reader is ready
        System.out.println(pr.ready());

        // read the first five chars
        for (int i = 0; i < 5; i++) {
            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 w w . j  a va  2 s. c  om
        int i = 70;

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

        raf.writeChar(i);

        raf.seek(0);

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

        raf.seek(0);

        raf.writeChar(71);

        raf.seek(0);

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

}

From source file:Main.java

public static void main(String[] args) {
    try {//from  w w  w.  j a v  a  2s  .c o  m
        int f = 1234;

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

        raf.writeInt(f);

        raf.seek(0);

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

        raf.seek(0);

        raf.writeInt(200);

        raf.seek(0);

        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 w  w w .j a  v  a  2  s. co  m
        byte[] b1 = { 15, 8 };

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

        raf.writeByte(b1[0]);

        raf.seek(0);

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

        raf.seek(0);

        raf.writeByte(b1[1]);

        raf.seek(0);

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

}

From source file:org.vuphone.vandyupon.test.EventMetaRequestTester.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=eventmetarequest&id=2&resp=xml";
    post.setEntity(new ByteArrayEntity(params.toString().getBytes()));

    try {//from   w w w. jav  a2  s .  c o m
        HttpResponse resp = c.execute(post);
        resp.getEntity().writeTo(System.out);
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:Main.java

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

    try {//  ww w .jav a 2  s. c  o m
        Thread t = new Main(port);
        t.start();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:MainClass.java

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

    try {//from   www  . java2s  . c  o m
        Thread t = new MainClass(port);
        t.start();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:org.vuphone.vandyupon.test.EventRatingPostTest.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=eventratingpost&event=1&user=chris&comment=awesome&value=1&resp=xml";
    post.setEntity(new ByteArrayEntity(params.toString().getBytes()));

    try {//  w ww.jav a  2  s  .com
        HttpResponse resp = c.execute(post);
        resp.getEntity().writeTo(System.out);
    } catch (IOException e) {
        e.printStackTrace();
    }

}

From source file:Main.java

public static void main(String[] args) {
    try {/*from  w  ww.j a v  a2  s .  c o m*/
        long l = 12345676789098L;

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

        // write something in the file
        raf.writeLong(l);

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

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

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

        // write something in the file
        raf.writeLong(12345676789099L);

        raf.seek(0);
        System.out.println(raf.readLong());
    } catch (IOException ex) {
        ex.printStackTrace();
    }

}