java - How can I get a specific line from a text file? -
this question has answer here:
i don't know how specific line of text file. let's text file is:
(1) john (2) mark (3) luke
how can second line of text file (mark)? need read it, not edit it.
int n = 2; string linen = files.lines(paths.get("yourfile.txt")) .skip(n) .findfirst() .get();
for pre-java 8, instance
int n = 2; scanner s = new scanner(new file("test.txt")); (int = 0; < n-1; i++) // discard n-1 lines s.nextline(); string linen = s.nextline();
Comments
Post a Comment