How to solve the problem with returning the value of the resource.getPath() from resources?

0 like 0 dislike
42 views
There is a file in the Resources connection.yaml:
YamlReader reader = null; try { URL resource = Client.class.getClassLoader().getResource("connection.yaml"); System.out.println("resource.toString() = " + resource.toString()); System.out.println("resource.getFile() = " + resource.getPath()); reader = new YamlReader(new FileReader(new File(resource.toURI()))); } catch (FileNotFoundException e) { e.printStackTrace(); }


the result

resource.toString() = file:/C:/Servers/Repository/Templates/out/production/resources/connection.yaml resource.getFile() = /C:/Servers/Repository/Templates/out/production/resources/connection.yaml


how to get rid of the "/"?
asked by | 42 views

1 Answer

0 like 0 dislike
YamlReader yamlReader = null; try (InputStream resourceAsStream = DrugDealerValidator.class.getResourceAsStream("connection.yaml"); Reader reader = new an InputStreamReader(resourceAsStream); YamlReader yamlReader = new YamlReader(reader)) { // work with yamlReader }catch (IOException e) { e.printStackTrace(); }
answered by

Related questions

0 like 0 dislike
1 answer
asked Oct 4, 2018 by mrKhatter
0 like 0 dislike
1 answer
asked Nov 1, 2018 by dr4k
0 like 0 dislike
1 answer
24,509 questions
45,932 answers
0 comments
346 users