Try converting the URL
to its URI
equivalent:
FileHelper.read(new File(getClass.getResource("TextFile.rtf").toURI()))
See URL.toURI()
for more information.
Question
I am trying to read a file using URL in java.
FileHelper.read(new File(getClass.getResource("TextFile.rtf")))
I am really confused with the below exception
error: overloaded method constructor File with alternatives:
(java.net.URI)java.io.File <and>
(java.lang.String)java.io.File
cannot be applied to (java.net.URL)
Any idea or suggestion how can I resolve this exception.
Thanks !!!
La solution
Try converting the URL
to its URI
equivalent:
FileHelper.read(new File(getClass.getResource("TextFile.rtf").toURI()))
See URL.toURI()
for more information.
Autres conseils
All you need to do is to get URI from the URL.
URL url = getClass.getResource("TextFile.rtf");
URI uri = url.toURI();
FileHelper.read(new File(uri))