[英]Why can't I create a File instance with this URI?
有谁知道为什么这个演员表不好:
URI myUri = URI.create("http://storage.googleapis.com/autoplay_audio/titanium.mp3");
File f = new File(myUri);
除了文件uri(例如file://
),您不能使用其他任何东西。
构造函数File(URI)
具有以下条件检查:
String scheme = uri.getScheme();
if ((scheme == null) || !scheme.equalsIgnoreCase("file"))
throw new IllegalArgumentException("URI scheme is not \"file\"");
如果您打算连接到http
uri,则需要使用其他机制,例如URL 。
您只能将文件用于文件。 为了使您的示例正常工作,File需要了解HTTP协议。 您应该根据需要和环境使用Apache HttpClient或其他框架。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.