コード例 #1
0
ファイル: Helpers.cs プロジェクト: Jaex/SMBStats
        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;
        }
コード例 #2
0
ファイル: MarkdownText.cs プロジェクト: pierre3/MarkdownMemo
        /// <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;
        }
コード例 #3
0
ファイル: MarkdownText.cs プロジェクト: pierre3/MarkdownMemo
        /// <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;
        }