读文件到byte[]的函数:
public static bool readFile(string filePathName, out byte[] bytes)
- {
- FileStream stream = new FileStream(filePathName, FileMode.Open);
- bool ret = false;
- bytes = null;
- if (null != stream)
- {
- int len = (int)stream.Length;
- bytes = new byte[len];
- int readLend = stream.Read(bytes, 0, len);
- stream.Flush();
- stream.Close();
- ret = readLend == len;
- }
- return ret;
- }
private void write2File(string filePathName, byte[] bytes)
- {
- if(File.Exists(filePathName))
- {
- File.Delete(filePathName);
- }
- FileStream stream = new FileStream(filePathName, FileMode.Create);
- stream.Write(bytes, 0, bytes.Length);
- stream.Flush();
- stream.Close();
- }