Search code examples
javanio

Read file with Java


I want to read SSL Certificate file with java from the location:

 URL url = TestSSLPacketChannel.class.getResource("/client.public");
    Path resPath = Paths.get(url.toURI());
    String file = new String(Files.readAllBytes(resPath), "UTF8");

This code successfully finds the file located at src\test\resources but when I send the file to this Java method:

new FileInputStream(SSL_Cert);

I get exception: java.io.FileNotFoundException: Invalid file path

Unfortunately I can;t change the method new FileInputStream(SSL_Cert); because I will break the code logic.

Is there any way to solve this problem?


Solution

  • Try putting the whole file path. "C:\User\Folder\file..."