File tree Expand file tree Collapse file tree 3 files changed +65
-0
lines changed Expand file tree Collapse file tree 3 files changed +65
-0
lines changed Original file line number Diff line number Diff line change 1+ package part4io ;
2+
3+ class Person {
4+ String lastName ;
5+
6+ public String getLastName () {
7+ return lastName ;
8+ }
9+
10+ public void setLastName (String lastName ) {
11+ this .lastName = lastName ;
12+ }
13+ }
14+
15+ public class Comparator {
16+
17+ public static void main (String [] args ) {
18+ java .util .Comparator <Person > c = java .util .Comparator .comparing (Person ::getLastName );
19+ //.thenComparing(Person::getFirstName)
20+
21+ //c.reversed(); Reversed
22+
23+ }
24+ }
Original file line number Diff line number Diff line change 1+ package part4io ;
2+
3+ import java .io .IOException ;
4+ import java .nio .file .Files ;
5+ import java .nio .file .Path ;
6+ import java .nio .file .Paths ;
7+ import java .util .stream .Stream ;
8+
9+ public class ExploringDirectories {
10+
11+ public static void main (String [] args ) throws IOException {
12+ Path p = Paths .get ("c:" , "Vodafone" );
13+
14+
15+ try (Stream <Path > s = Files .list (p )) {
16+ s .filter (path -> path .toFile ().isDirectory ()).forEach (System .out ::println );
17+ }
18+
19+ try (Stream <Path > s = Files .walk (p , 2 )) {
20+ s .filter (path -> path .toFile ().isDirectory ()).forEach (System .out ::println );
21+ }
22+ }
23+ }
Original file line number Diff line number Diff line change 1+ package part4io ;
2+
3+ import java .io .IOException ;
4+ import java .nio .file .Files ;
5+ import java .nio .file .Path ;
6+ import java .nio .file .Paths ;
7+ import java .util .stream .Stream ;
8+
9+ public class ReadingTextFiles {
10+
11+ public static void main (String [] args ) throws IOException {
12+ Path path = Paths .get ("d:" , "tmp" , "file.txt" );
13+
14+ try (Stream <String > s = Files .lines (path )) {
15+ s .filter (line -> line .contains ("ERROR" )).findFirst ().ifPresent (System .out ::println );
16+ }
17+ }
18+ }
You can’t perform that action at this time.
0 commit comments