Пример #1
0
        public static string Read(Stream fs)
        {
            var reader  = new StreamReader(fs, TxtEncoder.GetEncoding(fs));
            var content = reader.ReadToEnd();

            reader.Close();
            return(content);
        }
Пример #2
0
        public static StreamWriter Writer(Stream fs, bool append)
        {
            var encoding = TxtEncoder.GetEncoding(fs);

            if (append)
            {
                fs.Seek(0, SeekOrigin.End);
            }
            return(new StreamWriter(fs, encoding));
        }
Пример #3
0
        public static StreamWriter Writer(string file, bool append)
        {
            var fs       = new FileStream(file, FileMode.OpenOrCreate, FileAccess.ReadWrite);
            var encoding = TxtEncoder.GetEncoding(fs);

            if (append)
            {
                fs.Seek(0, SeekOrigin.End);
            }
            return(new StreamWriter(fs, encoding));
        }
Пример #4
0
        /// <summary>
        /// 读文本文件
        /// </summary>
        /// <param name="file"></param>
        /// <returns></returns>
        public static string Read(string file)
        {
            if (!File.Exists(file))
            {
                return(string.Empty);
            }
            var fs      = new FileStream(file, FileMode.Open);
            var reader  = new StreamReader(fs, TxtEncoder.GetEncoding(fs));
            var content = reader.ReadToEnd();

            reader.Close();
            return(content);
        }
Пример #5
0
        public static StreamReader Reader(string file)
        {
            var fs = new FileStream(file, FileMode.Open);

            return(new StreamReader(fs, TxtEncoder.GetEncoding(fs)));
        }