从共享路径打开文件时获取 IOException
我们使用 Desktop.open()
来打开文件。在某些情况下,此方法会引发 IOException:
Error message: The system cannot find the file specified.
java.io.IOException: Failed to open file:////userprofiles01/XDdata01/mm015633/Desktop/New%20folder/product/My%20Product/scripts/Logs/%5B2012-02-21%20131622-379%5D%20Interaction/log.html.
但是,当文件位于“C:\”驱动器上时,相同的代码可以正常工作。仅在以下情况下才会出现此问题:
- 文件路径位于共享驱动器上(不在“C:”驱动器上)并且
- 文件路径包含空格或任何特殊字符(例如“[”和“]”)。
示例:
文件夹或文件名包含空格,即“(空格)”
\\userprofiles01\XDdata01\mm015633\Desktop\Hi(空格)Hello\log.html
\\userprofiles01\XDdata01\mm015633\Desktop\HiHello\log(space)1.html
文件夹名称包含特殊字符“[”和“]”
\\filesrvwhq\india\Automation\MyProject\Mustak\[spacetest]\log.html
对此有什么想法吗?
谢谢
We are using Desktop.open()
to open files. In some case this method is throwing an IOException:
Error message: The system cannot find the file specified.
java.io.IOException: Failed to open file:////userprofiles01/XDdata01/mm015633/Desktop/New%20folder/product/My%20Product/scripts/Logs/%5B2012-02-21%20131622-379%5D%20Interaction/log.html.
However the same code works fine when the file is located on the "C:\" drive. The issue only appears if:
- File path is on a shared drive (not on "C:" drive) and
- File path contains blank spaces or any special characters like "[" and "]".
Examples:
Folder or file name contains blank spaces ie "(space)"
\\userprofiles01\XDdata01\mm015633\Desktop\Hi(space)Hello\log.html
\\userprofiles01\XDdata01\mm015633\Desktop\HiHello\log(space)1.html
Folder name contains special characters "[" and "]"
\\filesrvwhq\india\Automation\MyProject\Mustak\[spacetest]\log.html
Any thoughts on this?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
经过一番研究后,在我看来这是一个已知的错误:
https://bugs.java.com/bugdatabase/view_bug?bug_id=6780505
一个可能的解决方法,我没有尝试过,可能在这个答案中描述:
https://stackoverflow.com/a/1363056/1050015
After a bit of reasearch, it appears to me that this is a known bug:
https://bugs.java.com/bugdatabase/view_bug?bug_id=6780505
A possible workaround, I did not tried it, may be described in this answer:
https://stackoverflow.com/a/1363056/1050015