[英]Vb.net System.IO.File.ReadAllBytes throws error when there is space in file name
I am using the System.IO.File.ReadAllBytes() method to read a file from the system. 我正在使用System.IO.File.ReadAllBytes()方法从系统读取文件。 Whenever there is a space in the file name it throws a "Could not find a part of the path" error. 只要文件名中有空格,它就会引发“找不到路径的一部分”错误。
I tried adding double quotes to both ends of the path. 我尝试在路径的两端添加双引号。 Then it threw illegal characters in path error. 然后,它在路径错误中添加了非法字符。
Also tried replacing space with %20. 还尝试用%20替换空间。 Threw illegal character error again. 再次抛出非法字符错误。
How to overcome this? 如何克服呢?
My code: 我的代码:
Dim fpath = "D:\DOWNLOADED_FILES\Cir 14_2019.pdf"
System.IO.File.ReadAllBytes(fpath)
Explorer showing file path: 资源管理器显示文件路径:
Change: 更改:
System.IO.File.ReadAllBytes(fpath)
to: 至:
System.IO.File.ReadAllBytes(String.Format("""{0}""", fpath))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.