Shafu
Shafu

Reputation: 41

FileReader#mark() is throwing java.io.IOException

This is a part of my java code, this code is throwing (java.io.IOException) at (A.java:8) please help.

import java.io.FileReader;


public class A {

    public A() throws Exception {
        FileReader r = new FileReader("a.txt");
        r.mark(0);

        for(int i=0; i<27; i++)
            System.out.println((char)r.read());

        r.reset();

        for(int i=0; i<27; i++)
            System.out.println((char)r.read());

        r.close();
    }

    public static void main(String arg[]) throws Exception {
        new A();
    }
}

Upvotes: 2

Views: 860

Answers (2)

Andrew Stubbs
Andrew Stubbs

Reputation: 4462

FileReader does not support the mark operation.

You can determine this by reading the JavaDoc linked and seeing it doesn't override it or markSupported() inherited from Reader:

public boolean markSupported()

Tells whether this stream supports the mark() operation. 
The default implementation always returns false. 
Subclasses should override this method.

Upvotes: 2

Jens
Jens

Reputation: 69470

FileReader do not support the mark() function

Here the related part of the code from grepcode:

public void mark(int readAheadLimit) throws IOException {
        throw new IOException("mark() not supported");
}

Upvotes: 2

Related Questions