当文件名中有空格时,Vb.net System.IO.File.ReadAllBytes引发错误

时间:2019-03-16 08:59:58

标签: vb.net file

我正在使用System.IO.File.ReadAllBytes()方法从系统读取文件。只要文件名中有空格,它就会引发“找不到路径的一部分”错误。

我尝试在路径的两端添加双引号。然后它在路径错误中添加了非法字符。

还尝试用%20替换空格。再次抛出非法字符错误。

如何克服这个问题?

我的代码:

Dim fpath = "D:\DOWNLOADED_FILES\Cir 14_2019.pdf"
System.IO.File.ReadAllBytes(fpath)

资源管理器显示文件路径: Explorer showing file path

1 个答案:

答案 0 :(得分:-2)

更改:

System.IO.File.ReadAllBytes(fpath)

收件人:

System.IO.File.ReadAllBytes(String.Format("""{0}""", fpath))