我正在尝试使用byte []变量读取长字符串,但它给出了以下错误:
{System.IO.PathTooLongException:指定的路径,文件名或两者都太长。完全限定的文件名必须少于260个字符,目录名必须少于248个字符。
任何人都可以帮忙,谢谢。
请查看以下代码。在第二行,我收到了上述错误。
string filename = "Ak8AdFf/gICvXL9Ls3fDVMlLk7WbnddtL6GsobiBzXVLs4SurY6vhsOuMIRduX+PYmY1TYRmh026PbZlw0TNU711pLXGdc1qNqusr7if2WreciqKMJixqceH5WgrcTR2O5NAuXa/l8apkcSd3VQ/dVm3YJ7HxNSp1LvXi+CFWoR5nlNpeIffueCo6Kl1b4JxgGWSeqiBj1qbSKVQs0KoU7tDxUetbDodIai69vd8jSAIIKCEKvXL6BBBBBBBBBBBBBBBBBBBAAAAAAAAAAAAAACCCAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==";
byte[] bmpbyteArray = System.IO.File.ReadAllBytes(filename);
答案 0 :(得分:2)
您误解了NODE EXPLANATION
----------------------------------------------------------------------
<%-- '<%--'
----------------------------------------------------------------------
( group and capture to \1:
----------------------------------------------------------------------
(?: group, but do not capture (0 or more
times (matching the least amount
possible)):
----------------------------------------------------------------------
< '<'
----------------------------------------------------------------------
\/? '/' (optional (matching the most
amount possible))
----------------------------------------------------------------------
[a-z]+ any character of: 'a' to 'z' (1 or
more times (matching the most amount
possible))
----------------------------------------------------------------------
(?= look ahead to see if there is:
----------------------------------------------------------------------
[\s>] any character of: whitespace (\n,
\r, \t, \f, and " "), '>'
----------------------------------------------------------------------
) end of look-ahead
----------------------------------------------------------------------
(?: group, but do not capture (0 or more
times (matching the most amount
possible)):
----------------------------------------------------------------------
[^>=] any character except: '>', '='
----------------------------------------------------------------------
| OR
----------------------------------------------------------------------
= '='
----------------------------------------------------------------------
(?: group, but do not capture:
----------------------------------------------------------------------
' '\''
----------------------------------------------------------------------
[^']* any character except: ''' (0 or
more times (matching the most
amount possible))
----------------------------------------------------------------------
' '\''
----------------------------------------------------------------------
| OR
----------------------------------------------------------------------
" '"'
----------------------------------------------------------------------
[^"]* any character except: '"' (0 or
more times (matching the most
amount possible))
----------------------------------------------------------------------
" '"'
----------------------------------------------------------------------
| OR
----------------------------------------------------------------------
[^'"\s]* any character except: ''', '"',
whitespace (\n, \r, \t, \f, and "
") (0 or more times (matching the
most amount possible))
----------------------------------------------------------------------
) end of grouping
----------------------------------------------------------------------
)* end of grouping
----------------------------------------------------------------------
\s? whitespace (\n, \r, \t, \f, and " ")
(optional (matching the most amount
possible))
----------------------------------------------------------------------
\/? '/' (optional (matching the most
amount possible))
----------------------------------------------------------------------
> '>'
----------------------------------------------------------------------
| OR
----------------------------------------------------------------------
[^<] any character except: '<'
----------------------------------------------------------------------
)*? end of grouping
----------------------------------------------------------------------
) end of \1
----------------------------------------------------------------------
--%> '--%>'
----------------------------------------------------------------------
方法的参数。正如documentation中明确指出的那样,签名如下:
File.ReadAllBytes()
参数是路径 TO 二进制文件,而不是二进制文件本身。因此,文件名不能超过特定的字符长度。
答案 1 :(得分:0)
如果您没有阅读文件,则无需使用System.IO.File
课程。您似乎只是想获取字符串的字节数组。您需要使用编码类,例如System.Text.Encoding
var bts = System.Text.Encoding.ASCII.GetBytes(filename.ToCharArray());