OnJava8-Examples/files/ListOfLines.java

27 lines
656 B
Java
Raw Normal View History

2015-12-06 11:45:16 -08:00
// files/ListOfLines.java
2016-12-30 17:23:13 -08:00
// (c)2017 MindView LLC: see Copyright.txt
2015-12-06 11:45:16 -08:00
// We make no guarantees that this code is fit for any purpose.
2016-09-23 13:23:35 -06:00
// Visit http://OnJava8.com for more book information.
2015-12-06 11:45:16 -08:00
import java.util.*;
import java.nio.file.*;
public class ListOfLines {
2016-01-25 18:05:55 -08:00
public static void
main(String[] args) throws Exception {
2017-01-20 21:30:44 -08:00
Files.readAllLines(
Paths.get("../streams/Cheese.dat"))
.stream()
.filter(line -> !line.startsWith("//"))
.map(line ->
line.substring(0, line.length()/2))
.forEach(System.out::println);
2015-12-06 11:45:16 -08:00
}
}
/* Output:
Not much of a cheese
Finest in the
And what leads you
Well, it's
It's certainly uncon
*/