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 2s. c om*/
        RandomAccessFile raf = new RandomAccessFile("c:/test.txt", "rw");

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

        raf.seek(0);

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

        raf.seek(0);

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

        raf.seek(0);

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

}

From source file:Main.java

public static void main(String[] args) {

    PipedWriter writer = new PipedWriter();
    PipedReader reader = new PipedReader();

    try {/*from  w ww.  j av a 2  s  . c  om*/
        // connect the reader and the writer
        reader.connect(writer);

        writer.write(70);
        writer.write(71);

        // read what we wrote
        for (int i = 0; i < 2; i++) {
            System.out.println((char) reader.read());
        }

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

}

From source file:Main.java

public static void main(String[] args) {
    char[] c1 = { 'h', 'e', 'l', 'l', 'o' };
    char[] c2 = { 'w', 'o', 'r', 'l', 'd' };

    Writer writer = new PrintWriter(System.out);

    try {/*www .ja v a2  s .  c  o m*/
        // write a char array
        writer.write(c1);

        // flush the writer
        writer.flush();

        // write a new char array
        writer.write(c2);

        // flush the stream again
        writer.close();

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

From source file:Main.java

public static void main(String[] args) {
    PipedWriter writer = new PipedWriter();
    PipedReader reader = new PipedReader(100);

    try {//from ww  w. j  a va  2s.c  om
        // connect the reader and the writer
        reader.connect(writer);

        writer.write(70);
        writer.write(71);

        // check if reader is ready to read
        System.out.println(reader.ready());

        // print the char array
        for (int i = 0; i < 2; i++) {
            System.out.println("" + (char) reader.read());
        }

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

From source file:MainClass.java

public static void main(String[] args) {
    try {/*w w  w.  j  a  va  2s . c  o m*/
        Thread t = new MainClass();
        t.start();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:ReaderUtilClient.java

public static void main(String[] args) {
    ReaderUtil readerUtil = new ReaderUtil(new GenericObjectPool<StringBuffer>(new StringBufferFactory()));
    Reader reader = new StringReader("foo");
    try {/*from w w  w .j a  v  a  2  s.c om*/
        System.out.println(readerUtil.readToString(reader));
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:MainClass.java

public static void main(String args[]) {
    try {/*  w ww .j  a v a2s  .  c om*/
        System.out.print("Enter your name: ");
        InputStreamReader reader = new InputStreamReader(System.in);
        BufferedReader in = new BufferedReader(reader);

        String name = in.readLine();
        System.out.println("Hello, " + name + ". Enter three ints...");
        int[] values = new int[3];
        double sum = 0.0;

        for (int i = 0; i < values.length; i++) {
            System.out.print("Number " + (i + 1) + ": ");
            String temp = in.readLine();
            values[i] = Integer.parseInt(temp);
            sum += values[i];
        }

        System.out.println("The average equals " + sum / values.length);

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

From source file:Main.java

public static void main(String[] args) {

    PipedWriter writer = new PipedWriter();
    PipedReader reader = new PipedReader();

    try {/*w w w.j a  v a2 s  .c om*/
        // connect the reader and the writer
        writer.connect(reader);

        writer.write(70);
        writer.write(71);

        writer.close();

        // print what we wrote
        for (int i = 0; i < 2; i++) {
            System.out.println((char) reader.read());
        }

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

}

From source file:Main.java

public static void main(String[] args) {
    PipedWriter writer = new PipedWriter();
    PipedReader reader = new PipedReader();

    try {/*from w w w  .  j a v a  2s .  co  m*/
        // connect the reader and the writer
        reader.connect(writer);

        writer.write(70);
        writer.write(71);

        // read into a char array
        char[] b = new char[2];
        reader.read(b, 0, 2);

        // print the char array
        for (int i = 0; i < 2; i++) {
            System.out.println(b[i]);
        }

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

From source file:Main.java

public static void main(String[] args) {
    try {/*ww  w .  j  av  a 2 s.com*/
        int b1 = 15;
        int b2 = 20;

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

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

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

        raf.write(b2);

        raf.seek(1);

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

}