Please enable / Bitte aktiviere JavaScript!
Veuillez activer / Por favor activa el Javascript![ ? ]
How to solve the problem with returning the value of the resource.getPath() from resources? - bug-code.com Q&A

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

0 like 0 dislike
53 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 | 53 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
Welcome to Bug-code Q&A, where you can ask questions and receive answers from other members of the community.

24.8k questions

46.2k answers

0 comments

12.3k users

24,788 questions
46,220 answers
0 comments
12,337 users