File tree 4 files changed +49
-0
lines changed
main/java/com/examplehub/basics/io
test/java/com/examplehub/basics/io 4 files changed +49
-0
lines changed Original file line number Diff line number Diff line change
1
+ package com .examplehub .basics .io ;
2
+
3
+ public class FilesExample {}
Original file line number Diff line number Diff line change
1
+ package com .examplehub .basics .io ;
2
+
3
+ public class PathsExample {}
Original file line number Diff line number Diff line change
1
+ package com .examplehub .basics .io ;
2
+
3
+ import java .io .IOException ;
4
+ import java .nio .file .Files ;
5
+ import java .nio .file .Paths ;
6
+ import java .util .List ;
7
+ import org .junit .jupiter .api .Test ;
8
+
9
+ class FilesExampleTest {
10
+ @ Test
11
+ void testReadBytes () throws IOException {
12
+ byte [] bytes = Files .readAllBytes (Paths .get ("pom.xml" ));
13
+ System .out .println (new String (bytes ));
14
+ }
15
+
16
+ @ Test
17
+ void testReadString () throws IOException {
18
+ System .out .println (Files .readString (Paths .get ("pom.xml" )));
19
+ }
20
+
21
+ @ Test
22
+ void testReadAllLines () throws IOException {
23
+ List <String > lines = Files .readAllLines (Paths .get ("pom.xml" ));
24
+ for (String line : lines ) {
25
+ System .out .println (line );
26
+ }
27
+ }
28
+ }
Original file line number Diff line number Diff line change
1
+ package com .examplehub .basics .io ;
2
+
3
+ import static org .junit .jupiter .api .Assertions .assertEquals ;
4
+
5
+ import java .nio .file .Path ;
6
+ import java .nio .file .Paths ;
7
+ import org .junit .jupiter .api .Test ;
8
+
9
+ class PathsExampleTest {
10
+ @ Test
11
+ void get () {
12
+ Path path = Paths .get ("pom.xml" );
13
+ assertEquals ("pom.xml" , path .getFileName ().toString ());
14
+ }
15
+ }
You can’t perform that action at this time.
0 commit comments