public STDFManager(STDFFileMode mode, string fileName) { this.Processor = BYTE_ORIENTATION.UNKNOWN; this.Mode = mode; this.FileProcessing = fileName; if (this.Mode == STDFFileMode.Write) { try { if (fileName == @"c:\StdfTest.std") { File.Delete(fileName); } this.fs = new FileStream(fileName, FileMode.CreateNew, FileAccess.Write, FileShare.None, 0x4000); this.bw = new BinaryWriter(this.fs); this.Logger("File:{0} Created for output.\n", new object[] { fileName }); return; } catch { this.Logger("Unable to create file:{0} (File may already exist)\n", new object[] { fileName }); throw; } } if (this.Mode == STDFFileMode.Read) { try { this.fs = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read, 0x4000); this.Logger("File:{0} opened for Reading\n", new object[] { fileName }); this.FileLength = this.fs.Length; if (this.FileLength < 0x19L) { throw new Exception("File length less than 25 bytes " + fileName.ToString() + " is not a valid stdf file"); } //Read all bytes into an array from the specified file. int nBytes = (int)fs.Length; //计算流的长度 byte[] byteArray = new byte[nBytes]; //初始化用于MemoryStream的Buffer int nBytesRead = fs.Read(byteArray, 0, nBytes); //将File里的内容一次性的全部读到byteArray中去 MemoryStream stream = new MemoryStream(byteArray); //初始化MemoryStream,并将Buffer指向FileStream this.br = new BinaryReader(stream); this.Processor = BYTE_ORIENTATION.UNKNOWN; return; } catch { this.Logger("Unable to open file:{0} for reading\n", new object[] { fileName }); throw; } } throw new Exception("STDFManager:Unknown File Mode Requested"); }
public STDFManager(STDFFileMode mode, string fileName) { this.Processor = BYTE_ORIENTATION.UNKNOWN; this.Mode = mode; this.FileProcessing = fileName; if (this.Mode == STDFFileMode.Write) { try { if (fileName == @"c:\StdfTest.std") { File.Delete(fileName); } this.fs = new FileStream(fileName, FileMode.CreateNew, FileAccess.Write, FileShare.None, 0x4000); this.bw = new BinaryWriter(this.fs); this.Logger("File:{0} Created for output.\n", new object[] { fileName }); return; } catch { this.Logger("Unable to create file:{0} (File may already exist)\n", new object[] { fileName }); throw; } } if (this.Mode == STDFFileMode.Read) { try { this.fs = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read, 0x4000); this.Logger("File:{0} opened for Reading\n", new object[] { fileName }); this.FileLength = this.fs.Length; if (this.FileLength < 0x19L) { throw new Exception("File length less than 25 bytes " + fileName.ToString() + " is not a valid stdf file"); } //Read all bytes into an array from the specified file. int nBytes = (int)fs.Length;//计算流的长度 byte[] byteArray = new byte[nBytes];//初始化用于MemoryStream的Buffer int nBytesRead = fs.Read(byteArray, 0, nBytes);//将File里的内容一次性的全部读到byteArray中去 MemoryStream stream = new MemoryStream(byteArray);//初始化MemoryStream,并将Buffer指向FileStream this.br = new BinaryReader(stream); this.Processor = BYTE_ORIENTATION.UNKNOWN; return; } catch { this.Logger("Unable to open file:{0} for reading\n", new object[] { fileName }); throw; } } throw new Exception("STDFManager:Unknown File Mode Requested"); }
public STDFManager(STDFFileMode mode, string fileName) { this.Processor = BYTE_ORIENTATION.UNKNOWN; this.Mode = mode; this.FileProcessing = fileName; if (this.Mode == STDFFileMode.Write) { try { if (fileName == @"c:\StdfTest.std") { File.Delete(fileName); } this.fs = new FileStream(fileName, FileMode.CreateNew, FileAccess.Write, FileShare.None, 0x4000); this.bw = new BinaryWriter(this.fs); this.Logger("File:{0} Created for output.\n", new object[] { fileName }); return; } catch { this.Logger("Unable to create file:{0} (File may already exist)\n", new object[] { fileName }); throw; } } if (this.Mode == STDFFileMode.Read) { try { this.fs = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read, 0x4000); this.Logger("File:{0} opened for Reading\n", new object[] { fileName }); this.FileLength = this.fs.Length; if (this.FileLength < 0x19L) { throw new Exception("File length less than 25 bytes " + fileName.ToString() + " is not a valid stdf file"); } this.br = new BinaryReader(this.fs); this.Processor = BYTE_ORIENTATION.UNKNOWN; return; } catch { this.Logger("Unable to open file:{0} for reading\n", new object[] { fileName }); throw; } } throw new Exception("STDFManager:Unknown File Mode Requested"); }