Skip to content

Commit eef7b46

Browse files
realDuYuanChaogithub-actions
and
github-actions
authored
Files utils (#176)
* Files utils * Formatted with Google Java Formatter Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
1 parent 88ae704 commit eef7b46

File tree

4 files changed

+49
-0
lines changed

4 files changed

+49
-0
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package com.examplehub.basics.io;
2+
3+
public class FilesExample {}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package com.examplehub.basics.io;
2+
3+
public class PathsExample {}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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+
}

0 commit comments

Comments
 (0)