简体   繁体   中英

how to read File from a particular line till the end of the File in java

I have this File :

 Line1.
 Line2.
 Line3.
 Line4.

I want to start reading from the second line ( Line2 ) till the end of the file. How can i do this in Java?

If you want to read the file line by line, but skip the first line, I suggest you do

Files.lines(Paths.get("yourfile"))
     .skip(1)
     .forEach(...);

Note that this solution relies on an API that was added in Java 8 (released March last year), so if you haven't upgraded yet, you may want to do so.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM