-1

I want to read html template from resources folder into JUnit file. I tried this:

        String resourceName = "templates/account_confirmation.html";

        ClassLoader classLoader = getClass().getClassLoader();
        File file = new File(classLoader.getResource(resourceName).getFile());

        String content = Files.readString(file.toPath(), StandardCharsets.UTF_8);

I get error:

java: cannot find symbol
  symbol:   method readString(java.nio.file.Path,java.nio.charset.Charset)
  location: class java.nio.file.Files

Do you know how I can fix this issue?

Peter Penzov
  • 1,126
  • 134
  • 430
  • 808
  • You can read resources which are under test and I assume account_confirmation.html is in your main resource folder under src/main/java and not under src/test/java – anish sharma Jul 04 '21 at 11:07

1 Answers1

0

This was introduced in Java 11. Make sure the environment running it is using Java 11.

Vlad L
  • 1,544
  • 3
  • 6
  • 20