|
2 | 2 |
|
3 | 3 | import com.baeldung.abstractclasses.filereaders.BaseFileReader; |
4 | 4 | import com.baeldung.abstractclasses.filereaders.LowercaseFileReader; |
5 | | -import com.baeldung.abstractclasses.filereaders.StandardFileReader; |
6 | 5 | import com.baeldung.abstractclasses.filereaders.UppercaseFileReader; |
7 | 6 | import java.io.IOException; |
| 7 | +import java.net.URISyntaxException; |
| 8 | +import java.nio.file.Path; |
| 9 | +import java.nio.file.Paths; |
8 | 10 |
|
9 | 11 | public class Application { |
10 | 12 |
|
11 | | - public static void main(String[] args) throws IOException { |
12 | | - |
| 13 | + public static void main(String[] args) throws IOException, URISyntaxException { |
| 14 | + |
13 | 15 | Application application = new Application(); |
14 | | - String filePath = application.getFilePathFromResourcesFolder("files/test.txt"); |
15 | | - |
16 | | - BaseFileReader lowercaseFileReader = new LowercaseFileReader(filePath); |
| 16 | + Path path = application.getPathFromResourcesFile("files/test.txt"); |
| 17 | + BaseFileReader lowercaseFileReader = new LowercaseFileReader(path); |
17 | 18 | lowercaseFileReader.readFile().forEach(line -> System.out.println(line)); |
| 19 | + |
| 20 | + BaseFileReader uppercaseFileReader = new UppercaseFileReader(path); |
| 21 | + uppercaseFileReader.readFile().forEach(line -> System.out.println(line)); |
18 | 22 |
|
19 | | - BaseFileReader upperCaseFileReader = new UppercaseFileReader(filePath); |
20 | | - upperCaseFileReader.readFile().forEach(line -> System.out.println(line)); |
21 | | - |
22 | | - BaseFileReader standardFileReader = new StandardFileReader(filePath); |
23 | | - standardFileReader.readFile().forEach(line -> System.out.println(line)); |
24 | | - |
25 | 23 | } |
26 | 24 |
|
27 | | - private String getFilePathFromResourcesFolder(String fileName) { |
28 | | - return getClass().getClassLoader().getResource(fileName).getPath().substring(1); |
| 25 | + private Path getPathFromResourcesFile(String filePath) throws URISyntaxException { |
| 26 | + return Paths.get(getClass().getClassLoader().getResource(filePath).toURI()); |
| 27 | + |
29 | 28 | } |
30 | 29 | } |
0 commit comments