[英]Why can't I create a File instance with this URI?
Does anyone has an idea why this cast is not good: 有谁知道为什么这个演员表不好:
URI myUri = URI.create("http://storage.googleapis.com/autoplay_audio/titanium.mp3");
File f = new File(myUri);
You cannot use anything other than a file uri (eg file://
). 除了文件uri(例如
file://
),您不能使用其他任何东西。
The constructor File(URI)
has the following condition check: 构造函数
File(URI)
具有以下条件检查:
String scheme = uri.getScheme();
if ((scheme == null) || !scheme.equalsIgnoreCase("file"))
throw new IllegalArgumentException("URI scheme is not \"file\"");
If you intend to connect to an http
uri, you'll need to use some other mechanism, such as URL . 如果您打算连接到
http
uri,则需要使用其他机制,例如URL 。
You can use File only for files. 您只能将文件用于文件。 For your example to work, File would need to be aware of the HTTP protocol.
为了使您的示例正常工作,File需要了解HTTP协议。 You should use Apache HttpClient or some other framework depending on your needs and environment.
您应该根据需要和环境使用Apache HttpClient或其他框架。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.