Example usage for java.io PushbackReader close

List of usage examples for java.io PushbackReader close

Introduction

In this page you can find the example usage for java.io PushbackReader close.

Prototype

public void close() throws IOException 

Source Link

Document

Closes the stream and releases any system resources associated with it.

Usage

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

    char cbuf[] = new char[5];

    try {/*w  w w .j  a  va  2s .  c  om*/
        System.out.println(pr.read(cbuf));

        System.out.println(cbuf);

        pr.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.  j  a  v  a 2s.  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 = "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 {/* w w w  .  j  ava 2  s  .c  o m*/
        // 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) {

    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 ww w .  j a va  2 s. c  o  m
        // 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) {

    String s = "from java2s.com";

    StringReader sr = new StringReader(s);

    PushbackReader pr = new PushbackReader(sr, 20);

    try {// w w w.  jav a2 s. co  m
        for (int i = 0; i < 5; i++) {
            char c = (char) pr.read();
            System.out.println(c);
        }
        System.out.println("" + pr.markSupported());

        pr.close();

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

From source file:Main.java

public static void main(String[] args) {
    try {//from  ww w  . java2 s  . com
        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);

        // read the first five chars
        for (int i = 0; i < 5; i++) {
            char c = (char) pr.read();
            System.out.println(c);
        }
        // try to reset
        pr.reset();

        pr.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 www .j ava2s . c  om*/
        // read the first five chars
        for (int i = 0; i < 5; i++) {
            char c = (char) pr.read();
            System.out.println(c);

            // skip a character every time
            pr.skip(1);
        }

        pr.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 {//  w  ww  .  jav  a  2  s.  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) {

    String s = "from java2s.com";

    StringReader sr = new StringReader(s);

    PushbackReader pr = new PushbackReader(sr, 20);

    try {/*from w  ww  .j a  va2 s  .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);

        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) {
    String s = "from java2s.com";

    StringReader sr = new StringReader(s);

    PushbackReader pr = new PushbackReader(sr, 20);

    try {//from   w ww . j a v a2 s. co  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();
    }
}