【发布时间】:2015-06-15 18:33:56
【问题描述】:
我正在使用以下方法从互联网上下载文件:
try {
URL url = new URL("http://search.maven.org/remotecontent?filepath=com/cedarsoftware/json-io/4.0.0/json-io-4.0.0.jar");
FileUtils.copyURLToFile(url, new File(jsonerFolder.getParent() + "\\mods\\json-io-4.0.0.jar"));
} catch (Exception e1) {
logger.error("Downloading json-io failed with an exception");
e1.printStackTrace();
}
但是下载的文件不是jar,而是一个HTML文件,内容如下:
<html>
<head><title>302 Found</title></head>
<body bgcolor="white">
<center><h1>302 Found</h1></center>
<hr><center>nginx/0.8.55</center>
</body>
</html>
在浏览器(在我的例子中是 Google Chrome)中访问时直接下载,但在使用 FileUtils 时无法正确下载。
如何使用 FileUtils 正确下载文件?
【问题讨论】:
标签: java file url apache-commons fileutils