コード例 #1
0
 /// <summary>
 /// Creates a new text file if the specified file doesn't already exist
 /// </summary>
 /// <param name="filePath">The full file path of the file to be created</param>
 public virtual void CreateIfFileDoesNotExist(string filePath)
 {
     // This method should be called only if the TextFile object is in an INITIAL state.
     if (State != FileState.INITIAL)
     {
         throw new FileOpenException("File state is not INITIAL")
               {
                   FilePath = DirectoryPath,
                   FileName = FileName
               };
     }
     // Obtain the absolute file path.
     ParseFilePath(filePath);
     // Create an empty file if the specified file does not exist.
     if (!File.Exists(filePath))
     {
         FileOps.CreateFile(filePath);
     }
 }
コード例 #2
0
 /// <summary>
 /// Creates a new text file for writing
 /// </summary>
 /// <param name="filePath">
 /// The file path of the text file to be opened
 /// </param>
 public virtual void CreateForWrite(string filePath)
 {
     // Check to see if the file is already open. Throw an exception if it is.
     if (State == FileState.OPEN)
     {
         throw new FileOpenException("File already open")
               {
                   FilePath = DirectoryPath,
                   FileName = FileName
               };
     }
     // Obtain the absolute file path.
     ParseFilePath(filePath);
     // Throw an exception if the file already exists.
     FileOps.FileMustNotExist(FilePath);
     // Create the new text file
     FileOps.CreateFile(FilePath);
     // Finish opening the text file for writing
     State    = FileState.OPEN;
     Mode     = FileMode.WRITE;
     Position = 0;
 }