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 {//from  www.jav a2s .  c om

        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);

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

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

        raf.writeUTF("This is from java2s.com");

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

        // print the string
        System.out.println(raf.readUTF());
        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);

    PushbackReader pr = new PushbackReader(sr, 20);

    try {//from   w  w  w.  ja  v a  2s. c o m
        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, 1, 4);

        for (int i = 0; i < 4; 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 ww  .  ja  v  a 2  s  . co m
        byte[] b1 = { 1, 2, 3 };
        byte[] b2 = { 1, 2, 3, 4, 5, 6, 7, 8 };

        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 the first 8 bytes and print the number of bytes read
        System.out.println(raf.read(b1));

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

        // read the first 8 bytes and print the number of bytes read
        System.out.println(raf.read(b2));
        raf.close();
    } catch (IOException ex) {
        ex.printStackTrace();
    }

}

From source file:Main.java

public static void main(String[] args) {
    try {/*from  w ww  .  ja v  a2 s. co 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 5 position
        raf.seek(5);

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

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

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

}

From source file:Main.java

public static void main(String[] args) {
    try {//  w  w w . j  ava2 s .c o m
        RandomAccessFile raf = new RandomAccessFile("c:/test.txt", "rw");

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

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

        // print the line
        System.out.println(raf.readLine());

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

        raf.writeUTF("This is an example \n Hello World");

        raf.seek(0);
        // print the line
        System.out.println(raf.readLine());
        raf.close();
    } catch (IOException ex) {
        ex.printStackTrace();
    }

}

From source file:Main.java

public static void main(String[] args) {
    try {/*w ww . j av  a  2  s  .c  o m*/
        byte[] b1 = { 1, 2, 3 };
        byte[] b2 = { 1, 2, 3, 4, 5, 6, 7, 8 };

        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 2 bytes, starting from 1
        System.out.println(raf.read(b1, 1, 2));

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

        // read 3 bytes, starting from 4rth
        System.out.println(raf.read(b2, 4, 3));
        raf.close();
    } catch (IOException ex) {
        ex.printStackTrace();
    }

}

From source file:org.vuphone.vandyupon.test.EventPostTester.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=eventratingrequest&id=1&comments=true&numcom=10";
    post.setEntity(new ByteArrayEntity(params.toString().getBytes()));

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

}

From source file:org.vuphone.vandyupon.test.EventRequestTester.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=eventrequest&lat=36.1437&lon=-86.8046&dist=100&resp=xml&userid=chris";
    post.setEntity(new ByteArrayEntity(params.toString().getBytes()));

    try {/*  www.j  a v 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) throws Exception {
    Path path = Paths.get("test.txt");

    try (AsynchronousFileChannel afc = AsynchronousFileChannel.open(path, StandardOpenOption.WRITE,
            StandardOpenOption.CREATE)) {
        ByteBuffer dataBuffer = getDataBuffer();
        Future<Integer> result = afc.write(dataBuffer, 0);
        while (!result.isDone()) {
            System.out.println("Sleeping for 2  seconds...");
            Thread.sleep(2000);//from  w  ww.jav a 2s.  c  o m
        }
        int writtenBytes = result.get();
        System.out.format("%s bytes written  to  %s%n", writtenBytes, path.toAbsolutePath());

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

From source file:MainClass.java

public static void main(String[] args) {
    Employee e = new Employee();
    e.name = "Jor Lee";
    e.address = "USA";
    e.SSN = 11122333;/*from w w w.  j  a  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();
    }
}