我得到index out of bound on line: stream.Read(fileBytes[i], 0, fileBytes[i].Length);
任何帮助将是感激的.谢谢:)
string[] path = new string[15];
byte[][] fileBytes = new byte[10][];
for (int i = 1; i <= 10; i++) {
path[i] = @ "C:\Users\t-chkum\Desktop\InputFiles\1MB\" + i + ".txt ";
// readind data/*
FileStream stream = File.OpenRead(path[i]);
fileBytes[i] = new byte[stream.Length];
// Console.WriteLine(stream.Length);
stream.Read(fileBytes[i], 0, fileBytes[i].Length);
stream.Close();
}
你正在迭代从 i
=1
到 10
包罗万象。但是,数组的大小是 10
即指数从 0
到 9
. 所以,要么开始 i
从 0
或使用 i-1
. 另外,使用 try-catch
. 这将有助于你更好地调试。
否则,代码对我来说是正常工作的。