将文件名转换为URL()后,Java IO FileNotFoundException [英] Java IO FileNotFoundException after converting file name toURL()

查看:176
本文介绍了将文件名转换为URL()后,Java IO FileNotFoundException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是Jython代码(尽管这可能不是Jython特有的问题)...

Here is the Jython code (although this may not be a Jython-specific issue)...

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

java.io.FileNotFoundException:java.io.FileNotFoundException: 文件:/home/james/projects/wordnet/wordnet30/rdf/Manifest.ttl(没有这样的文件) 文件或目录)

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

推荐答案

通过转换给定的路径名​​字符串创建一个新的File实例 转换为抽象路径名.如果给定的字符串是空字符串, 那么结果就是空的抽象路径名.

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

File构造函数使用抽象路径名作为参数,而不是URL的toString表示形式.

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

此外,不建议使用toURL.您可以使用toURI,并使用此URI重建文件.

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

这篇关于将文件名转换为URL()后,Java IO FileNotFoundException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆