-4

I am new baby in Java Programming, i want to know what is efficient way to read specific line from text file in java?

Massnk Dev
  • 19
  • 1
  • 6
  • 9
    This question is already in other threads http://stackoverflow.com/questions/2138390/reading-a-specific-line-from-a-text-file-in-java – Mukesh Gupta Dec 08 '15 at 18:00
  • 1
    That question is tagged `apache-commons-io`, this one isn't. I'm sure there are earlier versions of this question (several of them), but that's not a good close-target (and my bad for not checking better before closing). – T.J. Crowder Dec 08 '15 at 18:06

1 Answers1

0

Use this but it has less efficiency!

String line = FileUtils.readLines(file).get(lineNumber);

If your files's lines has same size and you want to read line 15.

RandomAccessFile random=new RandomAccessFile("filename","r");
//let say Your line size if a;
random.seek(a*14);
random.readLine();

Use this if you don't have same size and let say you wanna read 15th line

BufferedReader random=new BufferedReader(new FileReader("filename"));
            int counter=0;
              while((line=random.readLine())!=null){
                  counter++;
                  if(counter==15){
                      //do whatever
                  }
              }  
Mukesh Gupta
  • 1,373
  • 3
  • 17
  • 42