开发者

Java IO FileNotFoundException after converting file name toURL()

开发者 https://www.devze.com 2023-03-31 15:42 出处:网络
Here is the Jython code (although this may not be a Jython-speci开发者_Go百科fic issue)... file_name = \"Manifest.ttl\"

Here is the Jython code (although this may not be a Jython-speci开发者_Go百科fic issue)...

file_name = "Manifest.ttl"
file_url = File(file_name).toURL()
f = File(file_url.toString())

java.io.FileNotFoundException: java.io.FileNotFoundException: file:/home/james/projects/wordnet/wordnet30/rdf/Manifest.ttl (No such file or directory)


Javadoc to the rescue:

Creates a new File instance by converting the given pathname string into an abstract pathname. If the given string is the empty string, then the result is the empty abstract pathname.

Parameters: pathname - A pathname string

The File constructor takes an abstract path name as argument, not the toString representation of a URL.

Besides, toURL is deprecated. You might use toURI, and reconstruct the file with this URI.


toURL() adds the file:// prefix that a proper URL/URI requires. Clearly the File constructor doesn't check and remove this prefix, so it's looking for a file called "file://..." instead of where you want it to look "/home/james/...".

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号