12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- using System;
- using System.IO;
- namespace RemoteControlLib.Codes
- {
-
-
-
- [Serializable]
- public class FileCode : BaseCode
- {
- private string fileName;
- private string savePath;
- private byte[] mbyte;
-
-
-
- private long fileLength;
-
-
-
- public byte[] Mbyte
- {
- get { return mbyte; }
- set { mbyte = value; }
- }
-
-
-
- public string SavePath
- {
- get { return savePath; }
- set { savePath = value; }
- }
-
-
-
-
- public FileCode(string fileName)
- {
- this.fileName = fileName;
- }
-
-
-
- public void readFile()
- {
- FileStream fileStream = new FileStream(fileName, FileMode.Open, FileAccess.Read);
- fileLength = fileStream.Length;
- mbyte = new byte[fileLength];
- int m = 0;
- int startmbyte = 0;
- int allmybyte = (int)fileLength;
- do
- {
- m = fileStream.Read(mbyte, startmbyte, allmybyte);
- startmbyte += m;
- allmybyte -= m;
- } while (m > 0);
- fileStream.Close();
- }
-
-
-
- public void SaveFile()
- {
- try
- {
- FileStream output = new FileStream(savePath, FileMode.OpenOrCreate, FileAccess.Write);
- output.Write(mbyte, 0, (int)fileLength);
- output.Close();
- }
- catch (Exception exp)
- {
- System.Windows.Forms.MessageBox.Show(exp.ToString());
- }
- }
- }
- }
|