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

    String s = "tutorial from java2s.com";

    Reader reader = new StringReader(s);

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

        // read the first five chars
        for (int i = 0; i < 5; i++) {
            char c = (char) reader.read();
            System.out.println(c);
        }
        reader.close();
    } catch (IOException ex) {
        ex.printStackTrace();
    }
}

From source file:DeleteDirectory.java

public static void main(String[] args) {
    try {//  ww w  .ja  v  a 2 s  .c  om
        Files.walkFileTree(Paths.get("/home"), new DeleteDirectory());
    } catch (IOException ex) {
        ex.printStackTrace();
    }
}

From source file:Main.java

public static void main(String[] args) {

    String s = "tutorial from java2s.com";

    Reader reader = new StringReader(s);

    // create a char array to read chars into
    char cbuf[] = new char[5];

    try {// w  w w. j  ava  2 s  . c  o  m
        // read characters into a portion of an array.
        System.out.println(reader.read(cbuf, 0, 5));

        System.out.println(cbuf);

        reader.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 a v  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());
        }
    } 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. j a va2 s.c  o m
        for (int i = 0; i < 5; i++) {
            char c = (char) pr.read();
            System.out.println(c);
        }
        pr.mark(5);
        pr.close();

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

From source file:Main.java

public static void main(String[] args) {

    String s = "tutorial from java2s.com";

    // create a new StringReader
    Reader reader = new StringReader(s);

    try {//from   w  w w. j a v  a  2s  .c o  m
        // read the first five chars
        for (int i = 0; i < 5; i++) {
            char c = (char) reader.read();
            System.out.println(c);
        }
        System.out.println(reader.markSupported());
        reader.close();

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

From source file:Main.java

public static void main(String[] args) {

    String s = "tutorial from java2s.com";

    Reader reader = new StringReader(s);

    // create a char array to read chars into
    char cbuf[] = new char[5];

    try {/*from w  ww .  ja  v a  2  s  . c  om*/
        // read characters into an array.
        System.out.println(reader.read(cbuf));

        System.out.println(cbuf);
        reader.close();

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

From source file:Main.java

public static void main(String[] args) {
    String text = "JFileChooser, you're my only friend.";

    JFileChooser chooser = new JFileChooser();
    int result = chooser.showSaveDialog(null);

    if (result == JFileChooser.APPROVE_OPTION) {
        try {//from w  w w  . j  a  v a  2 s  .  c o m
            File file = chooser.getSelectedFile();
            FileWriter writer = new FileWriter(file);
            writer.write(text);
            writer.close();
        } catch (IOException ex) {
            ex.printStackTrace();
        }
    }
}

From source file:Main.java

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

    Writer writer = new PrintWriter(System.out);

    try {/*from w w  w. j a  v a 2  s .  c  o m*/
        writer.append("This is an example\n");

        // flush the writer
        writer.flush();

        // append a new sequence
        writer.append(csq, 2, 30);

        // flush the writer to see the result
        writer.flush();

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

From source file:Main.java

public static void main(String[] args) {

    StringWriter sw = new StringWriter();

    // create a new sequence
    String s = "Hello from java2s.com";

    // write a string
    sw.write(s);/*from  ww w . j a  v  a 2s . c  o m*/

    System.out.println(sw.toString());

    try {
        // close the writer
        sw.close();
    } catch (IOException ex) {
        ex.printStackTrace();
        ;
    }

}