问题描述
我尝试使用方法(信用证):
I tried to use method (credits to Shenyuan Lu ):
org.apache.commons.io.FileUtils.copyURLToFile(URL,File)
准确地说:
org.apache.commons .io.FileUtils.copyURLToFile(driver.getCurrentUrl(),C:\\Users\\ myDocs \\myfolder\myFile.pdf);
然而, Eclipse
正在强调 copyURLToFile
并建议使用的CopyFile
。当我切换到 copyFile
时,它建议再次使用 copyURLToFile
???
However,Eclipse
is underlining the copyURLToFile
and suggesting to use copyFile
. When I switch to copyFile
, it suggests to use copyURLToFile
again???
推荐答案
根据 ...
第一个参数需要是 URL
对象,第二个参数需要是文件
宾语。你正在传递Strings作为两个args。尝试...
The first parameter needs to be a URL
object, and the second parameter needs to be a File
Object. You are passing Strings as both args. Try...
org.apache.commons.io.FileUtils.copyURLToFile(new URL(driver.getCurrentUrl()), new File("C:\\Users\\myDocs\\myfolder\\myFile.pdf"));
此外,由于此方法抛出异常,您需要使方法抛出异常,或者在try {} catch {}块中包含该语句。
Also, since this method throws an exception, you either need to make your method throw an exception, or surround the statement in a try {} catch{} block.
例如
try {
org.apache.commons.io.FileUtils.copyURLToFile(new URL(driver.getCurrentUrl()), new File("C:\\Users\\myDocs\\myfolder\\myFile.pdf"));
} catch (Exception x) { x.printStackTrace(); }
这篇关于如何正确使用FileUtils IO?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!