【发布时间】:2015-10-20 08:20:13
【问题描述】:
我有一个网址,即 http://downloadplugins.verify.com/Windows/SubAngle.exe 。 如果我将其粘贴到选项卡上并按 Enter,则文件(SubAngle.exe)将被下载并保存在下载文件夹中。这是手动过程。但可以使用 java 代码完成。 我编写了借助文件名即 SubAngle.exe 获取绝对路径的代码。
要求:- 借助 URL 文件被下载,验证文件是否已下载并返回文件的绝对路径。
where locfile is "http://downloadplugins.verify.com/Windows/SubAngle.exe"
public String downloadAndVerifyFile(String locfile) {
File fileLocation = new File(locfile);
File fileLocation1 = new File(fileLocation.getName());
String fileLocationPath = null;
if(fileLocation.exists()){
fileLocationPath = fileLocation1.getAbsolutePath();
}
else{
throw new FileNotFoundException("File with name "+locFile+" may not exits at the location");
}
return fileLocationPath;
}
【问题讨论】:
-
不,你应该有一个本地路径,它反映了你磁盘上的一个位置,比如 C:\Users\{你的用户名}\Downloads
标签: java