URL class giving error while opening a stream
I am using OpenJDK with spring boot and I want to download an image from the URL and store it in the physical file.
I used the channel class to read bytes fastly.
I tried to change the read file using file input stream and JAVA NIO but both are giving same error and I am not setting any trustAnchors because I do not want to use any certificate to. I want to use the default certificate.
ReadableByteChannel rbcObj = Channels.newChannel(urlObj.openStream());
FileOutputStream fOutStream = new FileOutputStream("/myfolder/abc.img");
fOutStream.getChannel().transferFrom(rbcObj, 0, Long.MAX_VALUE);
Open JDK throws below error
javax.net.ssl.SSLException: java.lang.RuntimeException: Unexpected error: java.security.InvalidAlgorithmParameterException: the trustAnchors parameter must be non-empty
at sun.security.ssl.Alerts.getSSLException(Alerts.java:208)
at sun.security.ssl.SSLSocketImpl.fatal(SSLSocketImpl.java:1937)
at sun.security.ssl.SSLSocketImpl.fatal(SSLSocketImpl.java:1894)
at sun.security.ssl.SSLSocketImpl.handleException(SSLSocketImpl.java:1877)
at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1398)
at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1375)
at sun.net.www.protocol.https.HttpsClient.afterConnect(HttpsClient.java:563)
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:185)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1512)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1440)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:254)
at java.net.URL.openStream(URL.java:1038)