/**超时连接的毫秒数 60秒*/
private static final int CONNECT_TIMEOUT = 60 * 1000;
/**超时下载的毫秒数,2个小时*/
private static final int READ_TIMEOUT = 2 * 60 * 60 * 1000;
private final static String Index_Spell = "kkk";
private final static String Root_Windows_Directory = "F:/data";
private final static String Root_Linux_Directory = "/data";
public static String downloadFile(String vcfurl,String fileName)
{
Map<String, Object> params = new HashMap<String, Object>();
params.put("downloadUrl", vcfurl);
String cloudurl = HttpUtil.post(PATH_DOWN, params);
String localurl = getSpellFile(fileName);
try
{
FileUtils.copyURLToFile(new URL(cloudurl), new File(localurl), CONNECT_TIMEOUT, READ_TIMEOUT);
}
catch (MalformedURLException e)
{
LogUtil.error("url格式异常"+e);
}
catch (IOException e)
{
LogUtil.error("IO异常"+e);
}
return localurl;
}
public static String getSpellFile(String fileName)
{
String vcfDir = null;
if (LocalIpUtil.isWinOS())
{
vcfDir = Root_Windows_Directory + File.separator + Index_Spell + File.separator + fileName;
}
else
{
vcfDir = Root_Linux_Directory + File.separator + Index_Spell + File.separator + fileName;
}
return vcfDir;
}
public static void main(String[] args)
{
String url = downloadFile("下载地址", "2016-08-17-15-18-53.vcf");
System.out.println(url);
}