Exemple #1
0
        public static byte[] FileGetBytes(string filePath, int maxLength = 0)
        {
            using (FileStream stream = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
            {
                if (maxLength == 0 || maxLength >= stream.Length)
                {
                    return stream.GetBytes();
                }
            }

            return null;
        }
Exemple #2
0
        /// <summary>
        /// 指定したエンコーディングでテキストファイルを読み込みます
        /// </summary>
        /// <param name="fileName">ファイル名</param>
        /// <param name="encoding">エンコーディング</param>
        public void OpenFrom(string fileName, Encoding encoding)
        {
            if(!File.Exists(fileName))
            throw new FileNotFoundException();
              if (encoding == null)
            throw new ArgumentNullException();

              using (var stream = new FileStream(fileName,FileMode.Open,FileAccess.Read))
              {
            this.Text = stream.GetBytes().ToDecodedString(encoding);
              }

              this.SourcePath = fileName;
              this.Encoding = encoding;
              this.IsTextChanged = false;
        }
Exemple #3
0
        /// <summary>
        /// エンコーディングを判別してテキストファイルを読み込みます。
        /// </summary>
        /// <param name="fileName">ファイル名</param>
        public void OpenFrom(string fileName)
        {
            if(!File.Exists(fileName))
            throw new FileNotFoundException();

              byte[] bytes;
              using(var stream = new FileStream(fileName,FileMode.Open,FileAccess.Read))
              {
            bytes = stream.GetBytes();
              }
              var encoding = bytes.GetCode();
            if(encoding == null)
              throw new NotSupportedException();

              this.Text = bytes.ToDecodedString(encoding);
              this.SourcePath = fileName;
              this.Encoding = encoding;
              this.IsTextChanged = false;
        }