当前位置: 首页>>代码示例>>C#>>正文


C# System.IO.FileStream.Read方法代码示例

本文整理汇总了C#中System.IO.FileStream.Read方法的典型用法代码示例。如果您正苦于以下问题:C# System.IO.FileStream.Read方法的具体用法?C# System.IO.FileStream.Read怎么用?C# System.IO.FileStream.Read使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.IO.FileStream的用法示例。


在下文中一共展示了System.IO.FileStream.Read方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: LoadImage

        public static BitmapImage LoadImage(string path)
        {
            try
            {
                var fs = new System.IO.FileStream(path, System.IO.FileMode.Open, System.IO.FileAccess.Read);
                fs.Seek(0, System.IO.SeekOrigin.Begin);
                byte[] bytes = new byte[fs.Length];
                fs.Read(bytes, 0, (int)fs.Length);
                fs.Close();

                var ms = new System.IO.MemoryStream(bytes);
                ms.Position = 0;
                var image = new BitmapImage();
                image.BeginInit();
                image.CreateOptions = BitmapCreateOptions.IgnoreColorProfile;
                image.CacheOption = BitmapCacheOption.OnLoad;
                image.StreamSource = ms;
                image.EndInit();
                return image;
            }
            catch (Exception ex)
            {
            }
            return null;
        }
开发者ID:ultrashot,项目名称:wpbackup,代码行数:25,代码来源:BitmapUtils.cs

示例2: readFile

        static byte[] readFile(string filename)
        {
            //let readFile filename =
            ////    let f = new IO.BufferedStream(new IO.FileStream(filename, IO.FileMode.Open, System.IO.FileAccess.Read))
            //    let f = new IO.FileStream(filename, IO.FileMode.Open, System.IO.FileAccess.Read)

            //    let fileSize = f.Length |> int
            //    let buf = Array.create(fileSize) 0uy        // 符号なし 8 ビット自然数?? http://msdn.microsoft.com/ja-jp/library/dd233193.aspx

            //    let mutable remain = fileSize;
            //    let mutable bufPos = 0;
            //    while remain > 0 do
            //        let readSize = f.Read(buf, bufPos, System.Math.Min(1024, remain))
            //        bufPos <- bufPos + readSize
            //        remain <- remain - readSize

            //    buf
            var f = new System.IO.FileStream(filename, System.IO.FileMode.Open, System.IO.FileAccess.Read);
            var fileSize = (int)f.Length;
            var buf = new byte[fileSize];
            int bufPos = 0;
            while (fileSize > 0) {
                int readSize = f.Read(buf, bufPos, System.Math.Min(1024, fileSize));
                bufPos += readSize;
                fileSize -= readSize;
            }
            return buf;
        }
开发者ID:sakujyo,项目名称:MySynthe,代码行数:28,代码来源:Form1.cs

示例3: RetrieveLinkerTimestamp

        private DateTime RetrieveLinkerTimestamp()
        {
            string filePath = System.Reflection.Assembly.GetCallingAssembly().Location;
            const int c_PeHeaderOffset = 60;
            const int c_LinkerTimestampOffset = 8;
            byte[] b = new byte[2048];
            System.IO.Stream s = null;

            try
            {
                s = new System.IO.FileStream(filePath, System.IO.FileMode.Open, System.IO.FileAccess.Read);
                s.Read(b, 0, 2048);
            }
            finally
            {
                if (s != null)
                {
                    s.Close();
                }
            }

            int i = System.BitConverter.ToInt32(b, c_PeHeaderOffset);
            int secondsSince1970 = System.BitConverter.ToInt32(b, i + c_LinkerTimestampOffset);
            DateTime dt = new DateTime(1970, 1, 1, 0, 0, 0);
            dt = dt.AddSeconds(secondsSince1970);
            dt = dt.AddHours(TimeZone.CurrentTimeZone.GetUtcOffset(dt).Hours);
            return dt;
        }
开发者ID:philoushka,项目名称:MediaSync,代码行数:28,代码来源:About.cs

示例4: GetBulidTime

        public static DateTime GetBulidTime()
        {
            var filePath = System.Reflection.Assembly.GetCallingAssembly().Location;
            const int cPeHeaderOffset = 60;
            const int cLinkerTimestampOffset = 8;
            var b = new byte[2048];
            System.IO.Stream s = null;

            try
            {
                s = new System.IO.FileStream(filePath, System.IO.FileMode.Open, System.IO.FileAccess.Read);
                s.Read(b, 0, 2048);
            }
            finally
            {
                if (s != null)
                {
                    s.Close();
                }
            }

            var i = BitConverter.ToInt32(b, cPeHeaderOffset);
            var secondsSince1970 = BitConverter.ToInt32(b, i + cLinkerTimestampOffset);
            var dt = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
            dt = dt.AddSeconds(secondsSince1970);
            dt = dt.ToLocalTime();
            return dt;
        }
开发者ID:Anuchap,项目名称:NUtils,代码行数:28,代码来源:AppInfo.cs

示例5: OtherWaysToGetReport

        private static void OtherWaysToGetReport()
        {
            string report = @"d:\bla.rdl";

            // string lalal = System.IO.File.ReadAllText(report);
            // byte[] foo = System.Text.Encoding.UTF8.GetBytes(lalal);
            // byte[] foo = System.IO.File.ReadAllBytes(report);

            using (System.IO.MemoryStream ms = new System.IO.MemoryStream())
            {

                using (System.IO.FileStream file = new System.IO.FileStream(report, System.IO.FileMode.Open, System.IO.FileAccess.Read))
                {
                    byte[] bytes = new byte[file.Length];
                    file.Read(bytes, 0, (int)file.Length);
                    ms.Write(bytes, 0, (int)file.Length);
                    ms.Flush();
                    ms.Position = 0;
                }

                using (System.IO.Stream stream = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("resource"))
                {
                    using (System.IO.TextReader reader = new System.IO.StreamReader(ms))
                    {
                        // rv.LocalReport.LoadReportDefinition(reader);
                    }
                }

                using (System.IO.TextReader reader = System.IO.File.OpenText(report))
                {
                    // rv.LocalReport.LoadReportDefinition(reader);
                }

            }
        }
开发者ID:ststeiger,项目名称:ReportViewerWrapper,代码行数:35,代码来源:SQL.cs

示例6: CompressOrDecompressFile

        /// <summary>
        /// Компрессия или декомпрессия файла
        /// </summary>
        /// <param name="fromFile">Исходный файл для компрессии или декомпрессии</param>
        /// <param name="toFile">Целевой файл</param>
        /// <param name="compressionMode">Указывает на компрессию или декомпрессию</param>
        private static void CompressOrDecompressFile(string fromFile, string toFile, System.IO.Compression.CompressionMode compressionMode)
        {
            System.IO.FileStream toFs = null;
            System.IO.Compression.GZipStream gzStream = null;
            System.IO.FileStream fromFs = new System.IO.FileStream(fromFile, System.IO.FileMode.Open, System.IO.FileAccess.Read);

            try
            {
                toFs = new System.IO.FileStream(toFile, System.IO.FileMode.Create, System.IO.FileAccess.Write);
                gzStream = new System.IO.Compression.GZipStream(toFs, compressionMode);
                byte[] buf = new byte[fromFs.Length];
                fromFs.Read(buf, 0, buf.Length);
                gzStream.Write(buf, 0, buf.Length);
            }
            finally
            {
                if (gzStream != null)
                    gzStream.Close();

                if (toFs != null)
                    toFs.Close();

                fromFs.Close();
            }
        }
开发者ID:UGTU,项目名称:UGTUKadrProject,代码行数:31,代码来源:CompressionHelper.cs

示例7: TorrentFile

        public TorrentFile(string FileName)
        {
            try
            {
                System.IO.FileStream TorrentFile = new System.IO.FileStream(FileName, System.IO.FileMode.Open);
                if (TorrentFile.Length == 0)
                    return;
                byte[] TorrentBytes = new byte[TorrentFile.Length];
                TorrentFile.Read(TorrentBytes, 0, TorrentBytes.Length);
                TorrentFile.Close();

                if ((char)TorrentBytes[0] != 'd')
                {

                    if (OpenError.Length == 0) OpenError = "�����Torrent�ļ�����ͷ��1�ֽڲ���100";
                    return;
                }
                GetTorrentData(TorrentBytes);
                if (TorrentName.Length == 0 && TorrentFileInfo.Count > 0)
                    TorrentName = TorrentFileInfo[0].Path;
            }
            catch (System.Exception ex)
            {
                //������־��¼
                //H31Debug.PrintLn("TorrentFile:" + ex.StackTrace);
            }
        }
开发者ID:kingorange2309,项目名称:H31DHTMgr,代码行数:27,代码来源:TorrentFile.cs

示例8: GetBuildTimestamp

        public static DateTime GetBuildTimestamp()
        {
            string filePath = Assembly.GetCallingAssembly().Location;
            const int c_PeHeaderOffset = 60;
            const int c_LinkerTimestampOffset = 8;
            byte[] b = new byte[2048];
            System.IO.Stream s = null;

            try
            {
                s = new System.IO.FileStream(filePath, System.IO.FileMode.Open, System.IO.FileAccess.Read);
                s.Read(b, 0, 2048);
            }
            finally
            {
                if (s != null)
                {
                    s.Close();
                }
            }

            int i = BitConverter.ToInt32(b, c_PeHeaderOffset);
            int secondsSince1970 = BitConverter.ToInt32(b, i + c_LinkerTimestampOffset);
            DateTime dt = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
            dt = dt.AddSeconds(secondsSince1970);
            dt = dt.ToUniversalTime();
            return dt;
        }
开发者ID:stefanprodan,项目名称:EsnServiceBus,代码行数:28,代码来源:ProcessHelpers.cs

示例9: GetBuildNumber

        //Code PES
        private string GetBuildNumber()
        {
            string strBuildNumber = string.Empty, timestamp = string.Empty;
            string filePath = System.Reflection.Assembly.GetCallingAssembly().Location;
            const int c_PeHeaderOffset = 60;
            const int c_LinkerTimestampOffset = 8;
            byte[] b = new byte[2048];
            System.IO.Stream s = null;

            try
            {
                s = new System.IO.FileStream(filePath, System.IO.FileMode.Open, System.IO.FileAccess.Read);
                s.Read(b, 0, 2048);
            }
            finally
            {
                if (s != null)
                {
                    s.Close();
                }
            }

            int i = System.BitConverter.ToInt32(b, c_PeHeaderOffset);
            int secondsSince1970 = System.BitConverter.ToInt32(b, i + c_LinkerTimestampOffset);
            DateTime dtDate = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
            dtDate = dtDate.AddSeconds(secondsSince1970);
            dtDate = dtDate.ToLocalTime();
            timestamp = dtDate.ToString("yyyyMMddHHmmss");
            if (timestamp == string.Empty)
            { timestamp = "UNKOWN!"; }
            strBuildNumber = "Build  : " + timestamp;
            return strBuildNumber;
        }
开发者ID:santoshsaha,项目名称:AxiomCS-Ribbon,代码行数:34,代码来源:About.xaml.cs

示例10: GetStream

 private string GetStream(string filePath)
 {
     System.IO.FileStream fileStr = new System.IO.FileStream(filePath, System.IO.FileMode.Open);
     byte[] by = new byte[System.Convert.ToInt32(fileStr.Length)];
     fileStr.Read(by, 0, by.Length);
     fileStr.Close();
     return (System.Convert.ToBase64String(by));
 }
开发者ID:devworker55,项目名称:Mammatus,代码行数:8,代码来源:SmtpServerHelper.cs

示例11: GetFileBody

 public static byte[] GetFileBody(String FileName) {
     using (System.IO.FileStream f = new System.IO.FileStream(FileName, System.IO.FileMode.Open)) {
         byte[] bytes = new byte[f.Length];
         Int32 readbytes = f.Read(bytes, 0, (Int32)f.Length);
         System.Diagnostics.Debug.Assert(f.Length == readbytes);
         return bytes;
     }
 }
开发者ID:bravesoftdz,项目名称:dvsrc,代码行数:8,代码来源:Utils.cs

示例12: Load

        public void Load()
        {
            System.IO.FileStream file = new System.IO.FileStream("data.dat",System.IO.FileMode.Open ) ;
            Byte[] buffer1 = System.BitConverter.GetBytes( Existe[0] ) ;
            Byte[] buffer2 = System.BitConverter.GetBytes( Left[0] ) ;
            Byte[] buffer3 = System.BitConverter.GetBytes( Top[0] ) ;
            Byte[] buffer4 = System.BitConverter.GetBytes( Color[0].ToArgb() ) ;
            Byte[] buffer5 = System.Text.Encoding.BigEndianUnicode.GetBytes( Text[0], 0 , Text[0].Length ) ;

            Byte[] bufferM1 = System.BitConverter.GetBytes( MainLeft ) ;
            Byte[] bufferM2 = System.BitConverter.GetBytes( MainTop ) ;
            file.Read( bufferM1, 0, bufferM1.Length ) ;
            MainLeft = System.BitConverter.ToInt32( bufferM1 , 0 ) ;
            file.Read( bufferM2, 0, bufferM2.Length ) ;
            MainTop = System.BitConverter.ToInt32( bufferM2 , 0 ) ;

            for ( int i = 0 ; i < MAX_POSTS ; i++ )
            {
                file.Read( buffer1, 0, buffer1.Length ) ;
                Existe[i] = System.BitConverter.ToBoolean( buffer1 , 0 ) ;
                file.Read( buffer2, 0, buffer2.Length ) ;
                Left[i] = System.BitConverter.ToInt32( buffer2 , 0 ) ;
                file.Read( buffer3, 0, buffer3.Length ) ;
                Top[i] = System.BitConverter.ToInt32( buffer3 , 0 ) ;
                file.Read( buffer4, 0, buffer4.Length ) ;
                Color[i] = System.Drawing.Color.FromArgb( System.BitConverter.ToInt32(buffer4, 0 ) ) ;
                file.Read( buffer5, 0, buffer5.Length ) ;
                Text[i] = System.Text.Encoding.BigEndianUnicode.GetChars( buffer5 ) ;
            }
            file.Close() ;
        }
开发者ID:riseven,项目名称:PostIt,代码行数:31,代码来源:Data.cs

示例13: GetPictureData

 private byte[] GetPictureData(string imagePath)
 {
     System.IO.FileStream fs = new System.IO.FileStream(imagePath, System.IO.FileMode.Open);
     byte[] byteData = new byte[fs.Length];
     fs.Read(byteData, 0, byteData.Length);
     fs.Close();
     return byteData;
     
 }
开发者ID:jiliyutou,项目名称:Kinect.Joy,代码行数:9,代码来源:WeiboShare.cs

示例14: Page_Load

        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                //文件路径,包括文件名:D:\Products\SRM\C-Procurement\Development\SRM\DataFolder\FileExport\WOItemSearchReport2005041415155.XLS
                string fullPathName = "";
                //文件名:WOItemSearchReport2005041415155.XLS
                string fileName = "";

                if (Page.Request["FilePath"] != null && Page.Request["FilePath"].ToString().Length > 0)
                {
                    fullPathName = HttpUtility.UrlDecode(Page.Request["FilePath"].ToString());
                    fileName = HttpUtility.UrlDecode(Page.Request["FileName"].ToString());
                }
                else
                {
                    Response.Write("<script>window.close();</script>");
                    return;
                }
                //System.IO.FileInfo fleInfo = new System.IO.FileInfo(fullPathName);
                //Response.Clear();
                //Response.ClearHeaders();
                //Response.Buffer = true;
                //Response.AddHeader("content-disposition", "attachment; filename=" + Server.UrlEncode(fileName.Trim()));
                ////inline(在线打开),attachment(下载)
                //Response.AddHeader("Content-Length", fleInfo.Length.ToString());
                //Response.ContentType = "application/x-msexcel";
                //Response.WriteFile(fullPathName);
                //Response.Flush();
                //Response.End();

                string fileserverpath = Server.MapPath(fullPathName);
                System.IO.FileInfo fi = new System.IO.FileInfo(fileserverpath);
                fi.Attributes = System.IO.FileAttributes.Normal;
                System.IO.FileStream filestream = new System.IO.FileStream(fileserverpath, System.IO.FileMode.Open);
                long filesize = filestream.Length;
                int i = Convert.ToInt32(filesize);

                Response.ContentType = "application/octet-stream";
                Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8));
                Response.AddHeader("Content-Length", filesize.ToString());
                byte[] fileBuffer = new byte[i];
                filestream.Read(fileBuffer, 0, i);
                filestream.Close();
                Response.BinaryWrite(fileBuffer);
                Response.Flush();
                Response.End();

            }
            catch (Exception Ex)
            {
                Response.Write("<script>alert('" + Ex.Message.Replace("'", "\\'") + "');window.close();</script>");
                Response.End();
            }
        }
开发者ID:chutinhha,项目名称:heradms,代码行数:55,代码来源:DownloadFile.aspx.cs

示例15: Main3

		/// <exception cref="System.IO.IOException"></exception>
		public static void Main3(string[] args)
		{
			System.IO.FileStream raf = new System.IO.FileStream("1141067269187.transaction", 
				"r");
			long length = raf.Length();
			System.Console.Out.WriteLine("File length = " + length);
			for (int i = 0; i < length; i++)
			{
				System.Console.Out.WriteLine(i + ":\t" + raf.Read());
			}
			raf.Close();
		}
开发者ID:ekicyou,项目名称:pasta,代码行数:13,代码来源:ByteFileReader.cs


注:本文中的System.IO.FileStream.Read方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。