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


C# FileStream.CopyStream方法代码示例

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


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

示例1: ExtractFiles

        private void ExtractFiles(FileStream fs, string extractFolderPath)
        {
            if (!Directory.Exists(extractFolderPath))
            {
                Directory.CreateDirectory(extractFolderPath);
            }

            for (int i = 0; i < directoryNameList.Length; i++)
            {
                string path = Path.GetFullPath(Path.Combine(extractFolderPath, directoryNameList[i].Name));

                if (!path.StartsWith(extractFolderPath)) throw new Exception("Invalid folder path: " + path);

                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }
            }

            Stopwatch timer = Stopwatch.StartNew();

            for (int i = 0; i < fileNameList.Length; i++)
            {
                if (timer.ElapsedMilliseconds > 100)
                {
                    bw.ReportProgress(0, new ProgressInfo(i, fileNameList.Length, fileNameList[i].Name));
                    timer.Reset();
                    timer.Start();
                }

                string path = Path.GetFullPath(Path.Combine(extractFolderPath, fileNameList[i].Name));

                if (!path.StartsWith(extractFolderPath)) throw new Exception("Invalid file path: " + path);

                if (!File.Exists(path))
                {
                    using (FileStream fs2 = new FileStream(path, FileMode.Create, FileAccess.Write, FileShare.Read))
                    {
                        fs.CopyStream(fs2, fileNameList[i].File.Offset, fileNameList[i].File.Size);
                    }
                }

                if (AutoConvertPNG && Path.GetExtension(path) == ".tp")
                {
                    using (MemoryStream ms = new MemoryStream())
                    {
                        fs.CopyStream(ms, fileNameList[i].File.Offset, fileNameList[i].File.Size);
                        DataHelpers.ConvertTPtoPNG(ms, path);
                    }
                }
            }

            bw.ReportProgress(0, new ProgressInfo(fileNameList.Length, fileNameList.Length, null));
        }
开发者ID:Jaex,项目名称:SMBStats,代码行数:54,代码来源:DataManager.cs

示例2: Close

        public override void Close()
        {
            long length = stream.Length;

            base.Close();
            stream.Close();

            if (length > 0)
            {
                //Write data to assembly
                using (FileStream tmpIn = new FileStream(assembly.Location, FileMode.Append))
                {
                    tmpIn.Write(signature, 0, signature.Length);

                    using (FileStream tmpOut = new FileStream(tmpContentFile, FileMode.Open))
                    {
                        tmpOut.CopyStream(tmpIn);
                        tmpOut.Close();
                    }

                    tmpIn.Close();
                }
            }
        }
开发者ID:CHiiLD,项目名称:net-toolkit,代码行数:24,代码来源:ApplicationStream.cs

示例3: Close

        /// <summary>
        /// Close the file appender stream
        /// </summary>
        /// <param name="writeBack">
        /// TRUE if the stream must be write the content of himself to the appender file.
        /// <remarks>
        /// The file must be closed to this time
        /// </remarks>
        /// </param>
        public virtual void Close(bool writeBack)
        {
            long length = stream.Length;
            stream.Close();

            if (length > 0)
            {
                //Write data to appender file
                using (FileStream tmpIn = new FileStream(Filename, FileMode.Append))
                {
                    tmpIn.Write(signature, 0, signature.Length);

                    using (FileStream tmpOut = new FileStream(tmpContentFile, FileMode.Open))
                    {
                        tmpOut.CopyStream(tmpIn);
                        tmpOut.Close();
                    }

                    tmpIn.Close();
                }
            }
        }
开发者ID:CHiiLD,项目名称:net-toolkit,代码行数:31,代码来源:FileAppenderStream.cs


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