コード例 #1
0
        /// <summary>
        /// 构造函数,创建一个指定文件地址的MemoryIOFile实例,并根据参数createdThenNotExists决定当文件不存在时是否创建新文件。
        /// </summary>
        /// <param name="fileUrl">指定的文件地址。</param>
        /// <param name="createdThenNotExists">用于决定是否在检测到文件不存在时来创建新文件。</param>
        /// <exception cref="FileNotFoundException">当指定的文件找不到时,则将会抛出这个异常。</exception>
        public MemoryIOFile(string fileUrl, bool createdThenNotExists)
        {
            bool isThrowedExceotion = false;

            if (createdThenNotExists)
            {
                if (!FileOperator.FileExists(fileUrl))
                {
                    FileOperator.CreateFile(fileUrl);
                }
                isThrowedExceotion = false;
            }
            else
            {
                if (!FileOperator.FileExists(fileUrl))
                {
                    isThrowedExceotion = true;
                    throw new FileNotFoundException("指定的文件找不到!", fileUrl);
                }
            }
            if (!isThrowedExceotion)
            {
                _fileUrl      = fileUrl;
                _memoryStream = new MemoryStream();
            }
        }
コード例 #2
0
 private const int DEFAULT_MEMORY_ALLOC_SIZE = 64; //内存流的默认空间初始分配长度。
 /// <summary>
 /// 构造函数,创建一个指定文件地址的MemoryIOFile实例。
 /// </summary>
 /// <param name="fileUrl">指定的文件地址。</param>
 /// <exception cref="FileNotFoundException">当指定的文件找不到时,则将会抛出这个异常。</exception>
 public MemoryIOFile(string fileUrl)
 {
     if (!FileOperator.FileExists(fileUrl))
     {
         throw new FileNotFoundException("指定的文件找不到!", fileUrl);
     }
     else
     {
         _fileUrl      = fileUrl;
         _memoryStream = new MemoryStream(DEFAULT_MEMORY_ALLOC_SIZE);
     }
 }