0

Is there any way to read a flat file from perticular line number? I heard about record-ident tag but not sure what to pass there.

There is no matching string, I need to read from a perticular libne number only.

1 Answers1

1

IOUtil is the utility class for accessing flat files.

IOUtil.lineIterator(Reader reader) can be useful for reading file from line nunber

LineIterator it = IOUtils.lineIterator(new BufferedReader(new FileReader("inputfile.txt")));
 for (int lineNoInFile = 0; it.hasNext(); lineNoInFile++) {
    String outputLine = (String) it.next();
    if (lineNoInFile == inputLineNumber) {
        return outputLine;
    }
 }

And to read multiple lines IOUtils.readLines can be used

int outputLinenumber = 25;      
List<String> lines = IOUtils.readLines(new FileInputStream(new File("inputfile.txt")), "UTF-8");
for (int index = outputLinenumber; index<=lines.size();index ++){
  //Iterate the Files
}

It's just sample code.

Mallikarjuna Reddy
  • 1,212
  • 2
  • 20
  • 33