Warm tip: This article is reproduced from stackoverflow.com, please click
java

How to move between rows in the file?

发布于 2020-03-27 15:40:30

If I have the file and there are 30 rows.How can I start reading from the 14th row?How to realize that in Java?are there any classes or methods in Java to move file pointer between rows?

Questioner
alelxf44
Viewed
18
Dupinder Singh 2020-01-31 16:15

I tried this on my eclipse and it worked for me.

package Codechef;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;

public class readLineFromFile {


     public static void main(String[] args) throws IOException {

            String line = Files.readAllLines(Paths.get("E:\\text.txt")).get(7);
            System.out.println(line);  
        }

}

output:

h
  • my text.txt file

    a
    b
    c
    d
    e
    f
    g
    h
    i
    k

this might help you