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 {//www. j  ava 2s .c  om
        boolean b = true;
        RandomAccessFile raf = new RandomAccessFile("c:/test.txt", "rw");

        raf.writeBoolean(false);

        raf.seek(0);

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

        raf.writeBoolean(b);

        raf.seek(1);

        System.out.println(raf.readBoolean());
        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
        Thread t = new Main();
        t.start();
    } 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 o  m*/
        // connect the reader and the writer
        writer.connect(reader);

        writer.write('A');
        writer.write('B');

        // 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) {
    int c = 70;//from  w ww . j  av a  2s  .  c om

    Writer writer = new PrintWriter(System.out);

    try {
        // write an int that will be printed as ASCII
        writer.write(c);

        // flush the writer
        writer.flush();

        // write another int that will be printed as ASCII
        writer.write(71);

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

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

From source file:Main.java

public static void main(String[] args) {
    try {// w  w  w .ja  va  2 s .com

        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 short
        System.out.println(raf.readUnsignedShort());

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

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

}

From source file:Main.java

public static void main(String[] args) {
    String s = "from java2s.com";

    Writer writer = new PrintWriter(System.out);

    try {//  w w w.  j a v  a 2  s. co  m
        // append a string
        writer.append(s);

        // flush the writer
        writer.flush();

        // append a new string
        writer.append("\nThis is an example");

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

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

From source file:Main.java

public static void main(String[] args) {
    String s = "from java2s.com";

    Writer writer = new PrintWriter(System.out);

    try {/*from w ww .  j  av a  2s  .c om*/
        // append a string
        writer.append(s);

        // flush the writer
        writer.flush();

        // append a new string in a new line
        writer.append("\nThis is an example");

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

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

From source file:Main.java

public static void main(String[] args) {
    File inputFile = new File("test1.txt");
    if (!inputFile.exists()) {
        System.out.println("The input file " + inputFile.getAbsolutePath() + "  does  not  exist.");
        System.out.println("Aborted the   file reading process.");
        return;/*from  ww  w  .j av  a2s. c o  m*/
    }
    try (FileChannel fileChannel = new FileInputStream(inputFile).getChannel()) {
        ByteBuffer buffer = ByteBuffer.allocate(1024);
        while (fileChannel.read(buffer) > 0) {
            buffer.flip();
            while (buffer.hasRemaining()) {
                byte b = buffer.get();
                System.out.print((char) b);
            }
            buffer.clear();
        }
    } 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  av a 2  s.c  o  m*/
        // connect the reader and the writer
        writer.connect(reader);

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

        // 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) {
    try {//from  w w  w  .  ja v  a 2 s.  c  o m
        RandomAccessFile raf = new RandomAccessFile("c:/test.txt", "rw");

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

        // return the file descriptor of the stream
        System.out.println(raf.getFD());

        // close the strea and release resources
        raf.close();
    } catch (IOException ex) {
        ex.printStackTrace();
    }

}