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


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

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


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

示例1: CreateFromDirectory

        public void CreateFromDirectory( string Dir, string Outfile )
        {
            string[] Filepaths = System.IO.Directory.GetFiles( Dir );

            ushort Filecount = (ushort)Filepaths.Length;
            uint RequiredBytesForHeader = Util.Align( Filecount * 3u + 5u, 0x10u ); // 3 bytes per filesize + 3 bytes for an extra pointer to first file + 2 bytes for filecount
            var Filestream = new System.IO.FileStream( Outfile, System.IO.FileMode.Create );

            // header
            Filestream.Write( BitConverter.GetBytes( Filecount ), 0, 2 );
            Filestream.Write( Util.GetBytesForUInt24( RequiredBytesForHeader ), 0, 3 );
            uint TotalFilesize = RequiredBytesForHeader;
            foreach ( string Path in Filepaths ) {
                TotalFilesize += (uint)( new System.IO.FileInfo( Path ).Length );
                Filestream.Write( Util.GetBytesForUInt24( TotalFilesize ), 0, 3 );
                TotalFilesize = TotalFilesize.Align( 0x10u );
            }
            while ( Filestream.Length < RequiredBytesForHeader ) { Filestream.WriteByte( 0x00 ); }

            // files
            foreach ( string Path in Filepaths ) {
                var File = new System.IO.FileStream( Path, System.IO.FileMode.Open );
                Util.CopyStream( File, Filestream, (int)File.Length );
                File.Close();
                while ( Filestream.Length % 0x10 != 0 ) { Filestream.WriteByte( 0x00 ); }
            }

            Filestream.Close();
        }
开发者ID:AdmiralCurtiss,项目名称:HyoutaTools,代码行数:29,代码来源:NPK.cs

示例2: Main

        static void Main(string[] args)
        {
            Console.Write("> Введите количество файлов: ");
            int n = 0;
            Int32.TryParse(Console.ReadLine(), out n);

            int[] setOfItems = new int[n];
            Random rnd = new Random();

            Dictionary<int, bool> tmpHash = new Dictionary<int, bool>();
            for (int i = 0; i < n * 2; ++i) {
                tmpHash[i] = false;
            }

            // Get a set of numbers
            int j = 0;
            while(j < n)
            {
                int randomNumber = rnd.Next(0, n * 2);
                if (!tmpHash[randomNumber]) {
                    Console.WriteLine(randomNumber.ToString());
                    setOfItems[j++] = randomNumber;
                    tmpHash[randomNumber] = true;
                }
            }
            Console.WriteLine("... набор данных готов!");

            // Saving to the file
            Console.Write("> Введите имя файла: ");
            String filename = "w:\\Zd02\\";
            filename += Console.ReadLine();
            int count = n;

            byte[] buffer = new byte[4];
            try
            {

                using (System.IO.FileStream fs = new System.IO.FileStream(filename,
                                                                          System.IO.FileMode.Create,
                                                                          System.IO.FileAccess.Write))
                {
                    buffer = BitConverter.GetBytes(count);
                    fs.Write(buffer, 0, buffer.Length);
                    for (int i = 0; i < count; ++i)
                    {
                        buffer = BitConverter.GetBytes(setOfItems[i]);
                        fs.Write(buffer, 0, buffer.Length);
                    }
                    fs.Close();
                }
                Console.WriteLine(String.Format("... файл сохранен как {0}!", filename));
            }
            catch (System.Exception ex)
            {
                Console.WriteLine("... Error! " + ex.ToString());
            }

            Console.ReadLine();
        }
开发者ID:agudulin,项目名称:proga,代码行数:59,代码来源:Program.cs

示例3: Main

        static void Main(string[] args)
        {
            try
            {
                // open file to output extracted fragments
                System.IO.FileInfo f1 = new System.IO.FileInfo("./out.txt");
                System.IO.FileStream fos = new System.IO.FileStream(f1.FullName, System.IO.FileMode.Create);

                // instantiate the parser
                VTDGen vg = new VTDGen();
                if (vg.parseFile("./soap2.xml", true))
                {
                    VTDNav vn = vg.getNav();
                    // get to the SOAP header
                    if (vn.toElementNS(VTDNav.FC, "http://www.w3.org/2003/05/soap-envelope", "Header"))
                    {
                        if (vn.toElement(VTDNav.FC))
                        // to first child
                        {
                            do
                            {
                                // test MUSTHAVE
                                if (vn.hasAttrNS("http://www.w3.org/2003/05/soap-envelope", "mustUnderstand"))
                                {
                                    long l = vn.getElementFragment();
                                    int len = (int)(l >> 32);
                                    int offset = (int)l;
                                    byte[] b = vn.getXML().getBytes();
                                    fos.Write(b, offset, len); //write the fragment out into out.txt
                                    System.Text.Encoding encoder = System.Text.Encoding.GetEncoding("ASCII");
                                    byte[] bytes = encoder.GetBytes("\n=========\n");

                                    fos.Write(bytes, 0, bytes.Length);
                                }
                            }
                            while (vn.toElement(VTDNav.NS)); // navigate next sibling	 
                        }
                        else
                            System.Console.Out.WriteLine("Header has not child elements");
                    }
                    else
                        System.Console.Out.WriteLine(" Dosesn't have a header");
                    
                    fos.Close();
                }
            }
            catch (NavException e)
            {
                System.Console.Out.WriteLine(" Exception during navigation " + e);
            }
            catch (System.IO.IOException e)
            {
                System.Console.Out.WriteLine(" IO exception condition" + e);
            }

        }
开发者ID:IgorBabalich,项目名称:vtd-xml,代码行数:56,代码来源:SOAPProcessor.cs

示例4: DownloadFile

 //---------- 一些静态方法 ----------
 // 下载文件到指定的路径
 public static void DownloadFile(string URL, string filename)
 {
     try
     {
         System.Net.HttpWebRequest Myrq = (System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create(URL);
         System.Net.HttpWebResponse myrp = (System.Net.HttpWebResponse)Myrq.GetResponse();
         long totalBytes = myrp.ContentLength;
         System.IO.Stream st = myrp.GetResponseStream();
         System.IO.Stream so = new System.IO.FileStream(filename, System.IO.FileMode.Create);
         long totalDownloadedByte = 0;
         byte[] by = new byte[1024];
         int osize = st.Read(by, 0, (int)by.Length);
         while (osize > 0)
         {
             totalDownloadedByte = osize + totalDownloadedByte;
             System.Windows.Forms.Application.DoEvents();
             so.Write(by, 0, osize);
             osize = st.Read(by, 0, (int)by.Length);
         }
         so.Close();
         st.Close();
     }
     catch (Exception ex)
     {
         logLog(ex.ToString());
     }
 }
开发者ID:Black-Spider,项目名称:why-wechat-printer,代码行数:29,代码来源:ImageTool.cs

示例5: Test

        // Following example show how to save file and read back from gridfs(using official mongodb driver):
        // http://www.mongovue.com/
        public void Test()
        {
            MongoDB.Driver.MongoServer server = MongoServer.Create("mongodb://localhost:27020");
            MongoDB.Driver.MongoDatabase database = server.GetDatabase("tesdb");

            string fileName = "D:\\Untitled.png";
            string newFileName = "D:\\new_Untitled.png";
            using (System.IO.FileStream fs = new System.IO.FileStream(fileName, System.IO.FileMode.Open))
            {
                MongoDB.Driver.GridFS.MongoGridFSFileInfo gridFsInfo = database.GridFS.Upload(fs, fileName);
                BsonValue fileId = gridFsInfo.Id;

                ObjectId oid = new ObjectId(fileId.AsByteArray);
                MongoDB.Driver.GridFS.MongoGridFSFileInfo file = database.GridFS.FindOne(Query.EQ("_id", oid));

                using (System.IO.Stream stream = file.OpenRead())
                {
                    byte[] bytes = new byte[stream.Length];
                    stream.Read(bytes, 0, (int)stream.Length);
                    using (System.IO.FileStream newFs = new System.IO.FileStream(newFileName, System.IO.FileMode.Create))
                    {
                        newFs.Write(bytes, 0, bytes.Length);
                    } // End Using newFs

                } // End Using stream

            } // End using fs
        }
开发者ID:moacap,项目名称:MongoUpload,代码行数:30,代码来源:MongoInit.cs

示例6: CreateFromDirectory

        public void CreateFromDirectory( string Dir, string Outfile )
        {
            string[] Filepaths = System.IO.Directory.GetFiles( Dir );

            ushort Filecount = (ushort)Filepaths.Length;
            uint RequiredBytesForHeader = Util.Align( Filecount * 4u + 4u, 0x50u ); // pretty sure this is not right but should work
            var Filestream = new System.IO.FileStream( Outfile, System.IO.FileMode.Create );

            // header
            Filestream.WriteByte( (byte)'S' ); Filestream.WriteByte( (byte)'C' );
            Filestream.WriteByte( (byte)'M' ); Filestream.WriteByte( (byte)'P' );
            uint TotalFilesize = RequiredBytesForHeader;
            foreach ( string Path in Filepaths ) {
                Filestream.Write( BitConverter.GetBytes( TotalFilesize ), 0, 4 );
                TotalFilesize += (uint)( new System.IO.FileInfo( Path ).Length );
                TotalFilesize = TotalFilesize.Align( 0x10u );
            }
            while ( Filestream.Length < RequiredBytesForHeader ) { Filestream.WriteByte( 0x00 ); }

            // files
            foreach ( string Path in Filepaths ) {
                var File = new System.IO.FileStream( Path, System.IO.FileMode.Open );
                Util.CopyStream( File, Filestream, (int)File.Length );
                File.Close();
                while ( Filestream.Length % 0x10 != 0 ) { Filestream.WriteByte( 0x00 ); }
            }

            Filestream.Close();
        }
开发者ID:AdmiralCurtiss,项目名称:HyoutaTools,代码行数:29,代码来源:SCMP.cs

示例7: CreateReportAsPDF

        public void CreateReportAsPDF(string grnNumbers, string fileName)
        {

            try
            {
                this.SP_GRNReportTableAdapter.Fill(this.grnReportDataSet.SP_GRNReport, grnNumbers);

                // Variables
                Warning[] warnings;
                string[] streamIds;
                string mimeType = string.Empty;
                string encoding = string.Empty;
                string extension = string.Empty;


                // Setup the report viewer object and get the array of bytes
                byte[] bytes = reportViewer1.LocalReport.Render("PDF", null, out mimeType, out encoding, out extension, out streamIds, out warnings);

                using (System.IO.FileStream sw = new System.IO.FileStream(fileName, System.IO.FileMode.Create))
                {
                    sw.Write(bytes, 0, bytes.Length);
                    sw.Close();
                }
            }
            catch (Exception ex)
            {

            }
        }
开发者ID:venkateshmani,项目名称:trinity,代码行数:29,代码来源:GrnReportControl.cs

示例8: CreateReportAsPDF

        public void CreateReportAsPDF(long? dyeingJoID, string fileName)
        {
            try
            {
                this.SP_CompactingJoDetailsTableAdapter.Fill(this.CompactingJoDataSet.SP_CompactingJoDetails, dyeingJoID);

                // Variables
                Warning[] warnings;
                string[] streamIds;
                string mimeType = string.Empty;
                string encoding = string.Empty;
                string extension = string.Empty;


                // Setup the report viewer object and get the array of bytes
                byte[] bytes = reportViewer1.LocalReport.Render("PDF", null, out mimeType, out encoding, out extension, out streamIds, out warnings);

                using (System.IO.FileStream sw = new System.IO.FileStream(fileName, System.IO.FileMode.Create))
                {
                    sw.Write(bytes, 0, bytes.Length);
                    sw.Close();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
开发者ID:venkateshmani,项目名称:trinity,代码行数:28,代码来源:CompactingJoControl.cs

示例9: UploadFile

        public void UploadFile(RemoteFileInfo request)
        {
            // report start
            Console.WriteLine("Start uploading " + request.FileName);
            Console.WriteLine("Size " + request.Length);

            // create output folder, if does not exist
            if (!System.IO.Directory.Exists("Upload")) System.IO.Directory.CreateDirectory("Upload");

            // kill target file, if already exists
            string filePath = System.IO.Path.Combine("Upload", request.FileName);
            if (System.IO.File.Exists(filePath)) System.IO.File.Delete(filePath);

            int chunkSize = 2048;
            byte[] buffer = new byte[chunkSize];

            using (System.IO.FileStream writeStream = new System.IO.FileStream(filePath, System.IO.FileMode.CreateNew, System.IO.FileAccess.Write))
            {
                do
                {
                    // read bytes from input stream
                    int bytesRead = request.FileByteStream.Read(buffer, 0, chunkSize);
                    if (bytesRead == 0) break;

                    // write bytes to output stream
                    writeStream.Write(buffer, 0, bytesRead);
                } while (true);

                // report end
                Console.WriteLine("Done!");

                writeStream.Close();
            }
        }
开发者ID:JonG87,项目名称:Terri,代码行数:34,代码来源:TerriService.cs

示例10: SaveFile

        private void SaveFile(byte[] byteArray)
        {
            // Displays a SaveFileDialog so the user can save the Image
            // assigned to Button2.
            SaveFileDialog saveFileDialog1 = new SaveFileDialog();
            saveFileDialog1.Filter = "MCEdit Schematic|*.schematic";
            saveFileDialog1.Title = "Save a Schematic File";
            saveFileDialog1.ShowDialog();

            // If the file name is not an empty string open it for saving.
            if (saveFileDialog1.FileName != "")
            {
                try
                {
                    // Open file for reading
                    System.IO.FileStream fs = new System.IO.FileStream(saveFileDialog1.FileName, System.IO.FileMode.Create, System.IO.FileAccess.Write);

                    // Writes a block of bytes to this stream using data from a byte array.
                    fs.Write(byteArray, 0, byteArray.Length);

                    // close file stream
                    fs.Close();
                }
                catch (Exception _Exception)
                {
                    // Error
                    Console.WriteLine("Exception caught in process: {0}", _Exception.ToString());
                }
            }
        }
开发者ID:TheGangster462,项目名称:MCPixelArt-Win,代码行数:30,代码来源:Form2.cs

示例11: ExtractVideoResourceToFile

        private void ExtractVideoResourceToFile(string targetFile)
        {
            // Create temporary output stream file name.
            System.IO.FileStream file = new System.IO.FileStream(
                targetFile, System.IO.FileMode.Create);

            Uri uri = new Uri(ResourceNames.IntroductionVideo, UriKind.RelativeOrAbsolute);
            StreamResourceInfo resourceInfo = Application.GetResourceStream(uri);
            System.IO.Stream resourceStream = resourceInfo.Stream;

            if (null != resourceStream)
            {
                try
                {
                    int offset = 0, bytesRead = 0;
                    byte[] buffer = new byte[4096];
                    while ((bytesRead = resourceStream.Read(buffer, offset, buffer.Length)) > 0)
                    {
                        file.Write(buffer, offset, bytesRead);
                    }

                    file.Flush();
                    file.Close();
                }
                catch (Exception)
                {
                }
            }
        }
开发者ID:samuto,项目名称:designscript,代码行数:29,代码来源:IntroVideoPlayer.xaml.cs

示例12: LogError

        public void LogError(Exception ex, string source)
        {
            try
            {
                String LogFile = HttpContext.Current.Request.MapPath("/Errorlog.txt");
                if (LogFile != "")
                {
                    String Message = String.Format("{0}{0}=== {1} ==={0}{2}{0}{3}{0}{4}{0}{5}"
                             , Environment.NewLine
                             , DateTime.Now
                             , ex.Message
                             , source
                             , ex.InnerException
                             , ex.StackTrace);
                    byte[] binLogString = Encoding.Default.GetBytes(Message);

                    System.IO.FileStream loFile = new System.IO.FileStream(LogFile
                              , System.IO.FileMode.OpenOrCreate
                              , System.IO.FileAccess.Write, System.IO.FileShare.Write);
                    loFile.Seek(0, System.IO.SeekOrigin.End);
                    loFile.Write(binLogString, 0, binLogString.Length);
                    loFile.Close();
                }
            }
            catch { /*No need to catch the error here. */}
        }
开发者ID:acrispin,项目名称:SampleProjectMvcTest,代码行数:26,代码来源:FileLogger.cs

示例13: CreateReportAsPDF

        public void CreateReportAsPDF(long? orderID, long? orderProductID, string fileName)
        {

            try
            {
                this.SP_MaterialDetailsTableAdapter.Fill(this.OrderManagerDBDataSet.SP_MaterialDetails, orderProductID, orderID);
                this.SP_MaterialOtherCostDetailsTableAdapter.Fill(this.OrderManagerDBOtherCostDataSet.SP_MaterialOtherCostDetails, orderProductID);

                // Variables
                Warning[] warnings;
                string[] streamIds;
                string mimeType = string.Empty;
                string encoding = string.Empty;
                string extension = string.Empty;


                // Setup the report viewer object and get the array of bytes
                byte[] bytes = reportViewer1.LocalReport.Render("PDF", null, out mimeType, out encoding, out extension, out streamIds, out warnings);

                using (System.IO.FileStream sw = new System.IO.FileStream(fileName, System.IO.FileMode.Create))
                {
                    sw.Write(bytes, 0, bytes.Length);
                    sw.Close();
                }
            }
            catch (Exception ex)
            {

            }
        }
开发者ID:venkateshmani,项目名称:trinity,代码行数:30,代码来源:BudgetReportControl.cs

示例14: CreateReportAsPDF

        public void CreateReportAsPDF(int? supplierID, long? jobOrderId, string fileName)
        {
            try
            {
                this.SP_JoGRNTableAdapter.Fill(this.joGRNReportDataSet.SP_JoGRN, supplierID, jobOrderId);

                // Variables
                Warning[] warnings;
                string[] streamIds;
                string mimeType = string.Empty;
                string encoding = string.Empty;
                string extension = string.Empty;

                reportViewer1.LocalReport.Refresh();
                // Setup the report viewer object and get the array of bytes
                byte[] bytes = reportViewer1.LocalReport.Render("PDF", null, out mimeType, out encoding, out extension, out streamIds, out warnings);

                using (System.IO.FileStream sw = new System.IO.FileStream(fileName, System.IO.FileMode.Create))
                {
                    sw.Write(bytes, 0, bytes.Length);
                    sw.Close();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
开发者ID:venkateshmani,项目名称:trinity,代码行数:28,代码来源:JoGRNReportControl.cs

示例15: Execute

        public static int Execute( List<string> args )
        {
            string filename = args[0];
            uint width = UInt32.Parse( args[1] );
            uint height = UInt32.Parse( args[2] );
            byte[] data = System.IO.File.ReadAllBytes( filename );

            string path = filename + ".dds";
            using ( var fs = new System.IO.FileStream( path, System.IO.FileMode.Create ) ) {
                fs.Write( Textures.DDSHeader.Generate( width, height, 1, format: Textures.TextureFormat.DXT5 ) );
                fs.Write( data );
                fs.Close();
            }

            return 0;
        }
开发者ID:AdmiralCurtiss,项目名称:HyoutaTools,代码行数:16,代码来源:Program.cs


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