我正在使用此代码从URL读取,代码正在给我这个错误:
Exception in thread "main" java.io.FileNotFoundException: C:\Work\Projects\WikipediaTemplate\codes\Sweble\WikipediaTemplateGenerator\tempFiles\htmlunit2229583992082609160.tmp (The system cannot find the file specified) at java.io.FileInputStream.open(Native Method) at java.io.FileInputStream.(FileInputStream.java:138) at com.gargoylesoftware.htmlunit.DownloadedContent$OnFile.getInputStream(DownloadedContent.java:81) at com.gargoylesoftware.htmlunit.WebResponseData.getStream(WebResponseData.java:91) at com.gargoylesoftware.htmlunit.WebResponseData.getInputStream(WebResponseData.java:156) at com.gargoylesoftware.htmlunit.WebResponse.getContentAsStream(WebResponse.java:241) at com.gargoylesoftware.htmlunit.util.WebResponseWrapper.getContentAsStream(WebResponseWrapper.java:58) at com.gargoylesoftware.htmlunit.DefaultPageCreator.createPage(DefaultPageCreator.java:150) at com.gargoylesoftware.htmlunit.WebClient.loadWebResponseInto(WebClient.java:468) at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:342) at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:407) at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:392) at etc.TestWebClient.main(TestWebClient.java:64)
我正在使用HTMLUnit 2.15。
代码是:
public static void main(String[] args) throws FailingHttpStatusCodeException, MalformedURLException, IOException {
File file=new File("tempFiles");
file.mkdir();
System.setProperty("java.io.tmpdir", file.getCanonicalPath());;
String url="http://www.nhs.uk/conditions/Norovirus/Pages/Introduction.aspx";
WebClient webClient = new WebClient(BrowserVersion.CHROME);
webClient.getOptions().setJavaScriptEnabled(false);
webClient.getOptions().setThrowExceptionOnFailingStatusCode(false);
webClient.getOptions().setThrowExceptionOnScriptError(false);
webClient.getOptions().setTimeout(120000);
webClient.getOptions().setUseInsecureSSL(true);
List<String> urlVisited=new ArrayList<String>();
System.err.println("URL Link:"+url);
int status =0;
status=webClient.getPage(url).getWebResponse()
.getStatusCode();
System.out.println("Web response status:"+status);
//webClient.getOptions().setJavaScriptEnabled(false);
String directory="";
LinkOption options = null;
//Files.getOwner(file.toPath(), options);
System.out.println(file.isDirectory()+"/"+file.canWrite());
// boolean bval = file.setWritable(true,false);
String currentDirectory = System.getProperty("user.dir");
System.out.println(currentDirectory);
//System.out.println(bval);
Page rawpage = webClient.getPage(url);
}