由於要把PC的程式移殖到PocketPC,結果PocketPC的System.IO.File沒有提供ReadAllBytes,於是上網找到此資料。
- public static byte[] ReadAllBytes(string path)
- {
- byte[] buffer;
- using (FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read))
- {
- int offset = 0;
- int count = (int)fs.Length;
- buffer = new byte[count];
- while (count > 0)
- {
- int bytesRead = fs.Read(buffer, offset, count);
- offset += bytesRead;
- count -= bytesRead;
- }
- }
- return buffer;
- }