Java - HtmlUnit - 无法将 HTML 保存到文件(在某些情况下)

发布于 2024-08-30 01:57:04 字数 2385 浏览 3 评论 0原文

我在 HtmlUnit 中保存响应 HTML 时遇到间歇性问题。

Caused by: java.io.IOException: Unable to save file:C:\ccview\PP50773_4.0_walter\TSC_hca\Applications\HCA_J2EE\HCA\target\HtmlUnitTests\single\1\com\pnc\tsc\hca\ui\test\SiteCrawler\crawlSiteAsProvider\10.SiteCrawler.crawl.html
    at com.pnc.tsc.hca.ui.util.GetUtil.save(GetUtil.java:128)
    at com.pnc.tsc.hca.ui.util.GetUtil.add(GetUtil.java:75)
    at com.pnc.tsc.hca.ui.util.GetUtil.click(GetUtil.java:49)
    at com.pnc.tsc.hca.ui.test.SiteCrawler.crawl(SiteCrawler.java:87)
    at com.pnc.tsc.hca.ui.test.SiteCrawler.crawl(SiteCrawler.java:61)
    at com.pnc.tsc.hca.ui.test.SiteCrawler.crawl(SiteCrawler.java:63)
    at com.pnc.tsc.hca.ui.test.SiteCrawler.crawl(SiteCrawler.java:63)
    at com.pnc.tsc.hca.ui.test.SiteCrawler.crawl(SiteCrawler.java:63)
    at com.pnc.tsc.hca.ui.test.SiteCrawler.crawl(SiteCrawler.java:54)
    at com.pnc.tsc.hca.ui.test.SiteCrawler.crawlSiteAsProvider(SiteCrawler.java:50)
    ... 15 more
Caused by: java.lang.RuntimeException: java.io.IOException: The system cannot find the path specified
    at com.gargoylesoftware.htmlunit.html.XmlSerializer.getAttributesFor(XmlSerializer.java:165)
    at com.gargoylesoftware.htmlunit.html.XmlSerializer.printOpeningTag(XmlSerializer.java:126)
    at com.gargoylesoftware.htmlunit.html.XmlSerializer.printXml(XmlSerializer.java:83)
    at com.gargoylesoftware.htmlunit.html.XmlSerializer.printXml(XmlSerializer.java:93)
    at com.gargoylesoftware.htmlunit.html.XmlSerializer.printXml(XmlSerializer.java:93)
    at com.gargoylesoftware.htmlunit.html.XmlSerializer.asXml(XmlSerializer.java:73)
    at com.gargoylesoftware.htmlunit.html.XmlSerializer.save(XmlSerializer.java:55)
    at com.gargoylesoftware.htmlunit.html.HtmlPage.save(HtmlPage.java:2259)
    at com.pnc.tsc.hca.ui.util.GetUtil.save(GetUtil.java:126)
    ... 24 more
Caused by: java.io.IOException: The system cannot find the path specified
    at java.io.WinNTFileSystem.createFileExclusively(Native Method)
    at java.io.File.createNewFile(File.java:883)
    at com.gargoylesoftware.htmlunit.html.XmlSerializer.createFile(XmlSerializer.java:216)
    at com.gargoylesoftware.htmlunit.html.XmlSerializer.getAttributesFor(XmlSerializer.java:160)
    ... 32 more

现在,父目录已存在,并且其他一些文件已写入该目录。查看文件名,我没有看到任何明显的危险信号,表明文件名是错误的。

我可以做什么来纠正这个错误?

谢谢,

沃尔特

I am having intermittent issues saving the response HTML in HtmlUnit.

Caused by: java.io.IOException: Unable to save file:C:\ccview\PP50773_4.0_walter\TSC_hca\Applications\HCA_J2EE\HCA\target\HtmlUnitTests\single\1\com\pnc\tsc\hca\ui\test\SiteCrawler\crawlSiteAsProvider\10.SiteCrawler.crawl.html
    at com.pnc.tsc.hca.ui.util.GetUtil.save(GetUtil.java:128)
    at com.pnc.tsc.hca.ui.util.GetUtil.add(GetUtil.java:75)
    at com.pnc.tsc.hca.ui.util.GetUtil.click(GetUtil.java:49)
    at com.pnc.tsc.hca.ui.test.SiteCrawler.crawl(SiteCrawler.java:87)
    at com.pnc.tsc.hca.ui.test.SiteCrawler.crawl(SiteCrawler.java:61)
    at com.pnc.tsc.hca.ui.test.SiteCrawler.crawl(SiteCrawler.java:63)
    at com.pnc.tsc.hca.ui.test.SiteCrawler.crawl(SiteCrawler.java:63)
    at com.pnc.tsc.hca.ui.test.SiteCrawler.crawl(SiteCrawler.java:63)
    at com.pnc.tsc.hca.ui.test.SiteCrawler.crawl(SiteCrawler.java:54)
    at com.pnc.tsc.hca.ui.test.SiteCrawler.crawlSiteAsProvider(SiteCrawler.java:50)
    ... 15 more
Caused by: java.lang.RuntimeException: java.io.IOException: The system cannot find the path specified
    at com.gargoylesoftware.htmlunit.html.XmlSerializer.getAttributesFor(XmlSerializer.java:165)
    at com.gargoylesoftware.htmlunit.html.XmlSerializer.printOpeningTag(XmlSerializer.java:126)
    at com.gargoylesoftware.htmlunit.html.XmlSerializer.printXml(XmlSerializer.java:83)
    at com.gargoylesoftware.htmlunit.html.XmlSerializer.printXml(XmlSerializer.java:93)
    at com.gargoylesoftware.htmlunit.html.XmlSerializer.printXml(XmlSerializer.java:93)
    at com.gargoylesoftware.htmlunit.html.XmlSerializer.asXml(XmlSerializer.java:73)
    at com.gargoylesoftware.htmlunit.html.XmlSerializer.save(XmlSerializer.java:55)
    at com.gargoylesoftware.htmlunit.html.HtmlPage.save(HtmlPage.java:2259)
    at com.pnc.tsc.hca.ui.util.GetUtil.save(GetUtil.java:126)
    ... 24 more
Caused by: java.io.IOException: The system cannot find the path specified
    at java.io.WinNTFileSystem.createFileExclusively(Native Method)
    at java.io.File.createNewFile(File.java:883)
    at com.gargoylesoftware.htmlunit.html.XmlSerializer.createFile(XmlSerializer.java:216)
    at com.gargoylesoftware.htmlunit.html.XmlSerializer.getAttributesFor(XmlSerializer.java:160)
    ... 32 more

Now, the parent directory exists and some other files have already been written to the directory. Looking at the filename, I don't see anything that would stand out as a red flag indicating the filename is bad.

What can I do to correct this error?

Thanks,

Walter

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

静待花开 2024-09-06 01:57:04

嗯,您完全在最大路径长度之内。异常跟踪显然认为这是路径问题。

我会尝试一些额外的测试来帮助隔离问题。在写入之前检查目录:File.exists()、File.isDirectory()、File.isWritable()。对文件本身进行类似的检查。可能想看看磁盘是否已满。

如果您能获得有关问题根源的更多信息,我们就能解决问题。

Well, you are well within the maximum path length. The exception trace clearly believes it is a path problem.

I would try some additional tests to help isolate the problem. Check the directory before writing with: File.exists(), File.isDirectory(), File.isWritable(). Similar checks on the file itself. May want to see if the disk is full too.

If you can get a little more information on the source of the problem, we can get it resolved.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文