"YOU AND THE ART OF ONLINE DATING" is the only product on the market that will take you step-by-step through the process of online dating, provide you with the resources to help ensure success. Get it now!
Scanner provides an abstraction over the underlying Readable whose content need not necessarily come from a File It doesn't directly support the kind of low-level query that you're looking for.
Scanner provides an abstraction over the underlying Readable, whose content need not necessarily come from a File. It doesn't directly support the kind of low-level query that you're looking for. You may be able to compute this number by combining the internal buffer position according to the Scanner and the number of bytes read according to the Readable, but even this looks to be a tricky proposition.
If an approximate location within a huge file is acceptable, then this may be good enough.
Its possibe using RandomAccessFile.. try this.. import java.io. FileNotFoundException; import java.io. IOException; import java.io.
RandomAccessFile; public class RandomFileAccessExample { RandomFileAccessExample() throws IOException { RandomAccessFile file = new RandomAccessFile("someTxtFile. Txt", "r"); System.out. Println(file.getFilePointer()); file.readLine(); System.out.
Println(file.getFilePointer()); } public static void main(String args) throws IOException { new RandomFileAccessExample(); } }.
Ok, but with RandomAccessFile I can't use Regular Expressions in such a easy way as with Scanner... – user288585 Mar 8 '10 at 8:41 thats right! But one way of doing is read all the lines, store it in a string and use regEx in the string.. I know! This sounds very bad!
:) – raj Mar 8 '10 at 8:56 it's impossible -- my files are to big to read it at once – user288585 Mar 8 '10 at 9:02 1 java as such do not provide tokenizer with RandomAccessFile. What else can we do!? Build up some logic.
Read line by line and tokenize it.! – raj Mar 8 '10 at 9:16.
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 { aiPos0++; return super.read(); } @Override public int read( byte be ) throws IOException { int iN = super. Read( be ); aiPos0 += iN; return iN; } @Override public int read( byte b, int off, int len ) throws IOException { int iN = super. Read( b, off, len ); aiPos0 += 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.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.