java - Get rid of a checked exception when using NIO2 API -


currently, loading property file classpath using following code of guava api:

final url fileurl = resources.getresource("res.properties"); final file file = new file(fileurl.getfile()); 

i decided give try new nio2 api introduced in java7se , remove guava api calls transformed code following:

final url fileurl = getclass().getresource("/res.properties"); final path path = paths.get(fileurl.touri()); 

but modified code throws checked exception in line conversion occurs between url , uri. there way can rid of it. can path instance given url, example?

p.s. aware modified code not semantically same original 1 - guava's getresource throws illegalargumentexception if resources not found, java's getresource returns null in case.

you use:

final file file = new file(fileurl.getfile()); final path path = file.topath(); //can throw unchecked exception 

Comments

Popular posts from this blog

Unable to remove the www from url on https using .htaccess -