apache commons io - Reading a specific line from a text file in Java -


is there method read specific line text file ? in api or apache commons. :

string readline(file file, int linenumber) 

i agree it's trivial implement, it's not efficient specially if file big.

string line = fileutils.readlines(file).get(linenumber); 

would do, still has efficiency problem.

alternatively, can use:

 lineiterator = ioutils.lineiterator(        new bufferedreader(new filereader("file.txt")));  (int linenumber = 0; it.hasnext(); linenumber++) {     string line = (string) it.next();     if (linenumber == expectedlinenumber) {         return line;     }  } 

this more efficient due buffer.

take @ scanner.skip(..) , attempt skipping whole lines (with regex). can't tell if more efficient - benchmark it.

p.s. efficiency mean memory efficiency


Comments

Popular posts from this blog

c++ - Convert big endian to little endian when reading from a binary file -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

unicode - Are email addresses allowed to contain non-alphanumeric characters? -