You can get an approximate file position by using a custom FileInputStream to create the Scanner, like this:
final int [] aiPos = new int [1];
FileInputStream fileinputstream = new FileInputStream( file ) {
@Override
public int read() throws IOException {
aiPos[0]++;
return super.read();
}
@Override
public int read( byte [] b ) throws IOException {
int iN = super.read( b );
aiPos[0] += iN;
return iN;
}
@Override
public int read( byte [] b, int off, int len ) throws IOException {
int iN = super.read( b, off, len );
aiPos[0] += iN;
return iN;
}
};
Scanner scanner = new Scanner( fileinputstream );
This will give you a position accurate to within 8K or so, depending on the implementation of FileInputStream. This is useful for things like updating progress bars during a file parse, where
you don't need the exact position, just something reasonably close.