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


C# BinaryWriter.Close方法代码示例

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


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

示例1: Decrypt

 //解密
 public string Decrypt(string m,string key)
 {
     string msg = null;
     string[] array = m.Split('~');
     int length = array.Length;
     byte[] by = new byte[length];
     for (int i = 0; i < length;i++ )
     {
         int l = int.Parse(array[i]);
         byte[] k = System.BitConverter.GetBytes(l);
         by[i] = k[0];
     }
     try
     {
         FileStream aFile = new FileStream("2.txt", FileMode.Create);
         BinaryWriter sw = new BinaryWriter(aFile);
         sw.Write(by);
         sw.Close();
         aFile.Close();
     }
     catch (IOException e){}
     test.DES_Decrypt("2.txt", key, "3.txt");
     try
     {
         FileStream file = new FileStream("3.txt", FileMode.Open);
         StreamReader read = new StreamReader(file);
         msg=read.ReadToEnd();
         read.Close();
         file.Close();
     }
     catch (IOException) { }
     return msg;
 }
开发者ID:wuqingzhou828,项目名称:client,代码行数:34,代码来源:DES.cs

示例2: Main

        static void Main(string[] args)
        {
            FileStream filStream;
            BinaryWriter binWriter;

            Console.Write("Enter name of the file: ");
            string fileName = Console.ReadLine();
            if (File.Exists(fileName))
            {
                Console.WriteLine("File - {0} already exists!", fileName);
            }
            else
            {
                filStream = new FileStream(fileName, FileMode.CreateNew);
                binWriter = new BinaryWriter(filStream);
                decimal aValue = 2.16M;
                binWriter.Write("Sample Run");
                for (int i = 0; i < 11; i++)
                {

                    binWriter.Write(i);
                }
                binWriter.Write(aValue);

                binWriter.Close();
                filStream.Close();
                Console.WriteLine("File Created successfully");
            }

            Console.ReadKey();
        }
开发者ID:moeen-aqrabawi,项目名称:C-.NET,代码行数:31,代码来源:BinaryExample.cs

示例3: DeCrypting

 private static string DeCrypting()
 {
     var res = string.Empty;
     var file = new FileStream(Controller.GetPath(), FileMode.Open, FileAccess.Read, FileShare.None, 32, FileOptions.SequentialScan);
     var reader = new BinaryReader(file);
     var writer = new BinaryWriter(new FileStream(Processor.GetNewName(Controller.GetPath()), FileMode.Create, FileAccess.Write,
         FileShare.None, 32, FileOptions.WriteThrough));
     try
     {
         var pos = 0;
         while (pos < file.Length)
         {
             var c = reader.ReadUInt16();
             //var pow = Processor.fast_exp(c, Controller.GetKc(), Controller.GetR());
             var pow = Processor.Pows(c, Controller.GetKc(), Controller.GetR());
             if (pos < 256) res += pow + " ";
             writer.Write((byte)(pow));
             pos += 2;
         }
     }
     finally
     {
         writer.Close();
         reader.Close();
     }
     return "Decoding Complete!\n" + res;
 }
开发者ID:Emaxan,项目名称:TI_Laba4_RSA,代码行数:27,代码来源:Decoding.cs

示例4: writeBinary

        public void writeBinary()
        {
            string nom = tbName.Text + ".bytes"; byte i;
            BinaryReader br = null;
            BinaryWriter bw = null;
            FileStream fs = null;
            //Ecriture d'octets dans le fichier
            bw = new BinaryWriter(File.Create(nom));

            i = Convert.ToByte(width.Text);
            bw.Write(i);

            i = Convert.ToByte(height.Text);
            bw.Write(i);

            i = Convert.ToByte(random.Checked);
            bw.Write(i);

            for (int j = 3; j < Convert.ToInt32(width.Text); j++)
            {
                bw.Write(Convert.ToSByte(0));
            }

            foreach (DataGridViewRow data in dataGridView1.Rows)
            {
                for(int j = 0; j < dataGridView1.Columns.Count;j++)
                {
                    i = Convert.ToByte(data.Cells[j].Value);

                    bw.Write(i);
                }
            }

            bw.Close();
        }
开发者ID:JustineSieye,项目名称:CACAHUETE_BOMBERBOT,代码行数:35,代码来源:Form1.cs

示例5: ImportMedia

 public void ImportMedia(string fileUri)
 {
     var fileName = Path.GetFileName(fileUri);
     var savePathForFile = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), fileName);
     if (!File.Exists(savePathForFile))
     {
         var client = new WebClient();
         BinaryWriter binaryWriter = null;
         try
         {
             byte[] data = client.DownloadData(fileUri);
             var fileStream = new FileStream(savePathForFile, FileMode.Create, FileAccess.Write);
             binaryWriter = new BinaryWriter(fileStream);
             binaryWriter.Write(data);
             binaryWriter.Close();
         }
         finally
         {
             client.Dispose();
             if (binaryWriter != null)
             {
                 binaryWriter.Close();
             }
         }
     }
 }
开发者ID:cerikpete,项目名称:AutismImporter,代码行数:26,代码来源:TaskRepository.cs

示例6: transfer

        /*Initiates a TFTP file transfer from the server to the local machine.*/
        public bool transfer(IPEndPoint server, String filename, bool error, TransferMode mode)
        {
            if (DEBUG) { Console.WriteLine("Retrieving file " + filename + " from server at " + server.ToString() + (error ? " with errors " : " without errors ") + "using transfer mode " + (mode == TransferMode.NETASCII ? "netascii." : "octet.")); }
                IPEndPoint sender = new IPEndPoint(IPAddress.Any, 0);
                byte[] block;
                byte[] message = new byte[416];
                UInt16 blocknum;
                Int32 msgBytes = 0;
                Int32 index = 0;
                BinaryWriter fileWriter;
                UdpClient client = new UdpClient();
                fileWriter = new BinaryWriter(File.Create(filename, 512));
                requestData(client, server, filename, error, mode);
                do
                {
                    block = recieveData(client, ref sender);
                    if (DEBUG) { Console.WriteLine("Recieved datagram with length " + block.Length + " from " + sender.ToString() + "with op code " + HammingCode.getOpCode(block) + ":\n" + ASCII.GetString(block)); }

                    if (HammingCode.getOpCode(block) == 3)
                    {
                        blocknum = HammingCode.getBlockNum(block);

                        if (DEBUG) { Console.WriteLine("Recieved data packet with block number: " + blocknum); }
                        if (HammingCode.getMessage(block, block.Length, ref message, ref msgBytes))
                        {
                            fileWriter.Write(message, 0, msgBytes);
                            index += msgBytes;
                            acknowledge(client, sender, blocknum);
                        }
                        else
                        {
                            nacknowledge(client, sender, blocknum);
                            continue;
                        }
                    }
                    else if (HammingCode.getOpCode(block) == 5) //error
                    {
                        Console.WriteLine("Error encountered. Terminating file transfer.");
                        client.Close();
                        fileWriter.Close();
                        File.Delete(filename);
                        return false;
                    }
                    else //wtf?
                    {
                        Console.WriteLine("Recieved packet with unexpected op code. Terminating file transfer.");
                        client.Close();
                        fileWriter.Close();
                        File.Delete(filename);
                        return false;
                    }
                }
                while (block.Length > 515);
                fileWriter.Close();
                return true;
        }
开发者ID:vnwhlr,项目名称:Schoolwork,代码行数:57,代码来源:TFTP.cs

示例7: Decrypt

        public static void Decrypt(string file_input, string file_output, string key1)
        {
            FileStream input;
            BinaryReader br;
            FileStream output;
            BinaryWriter bw;
            byte[] block;

            key = new Key(key1);
            Utils.key.makeKey();
            Utils.key.reverseKey();
            try
            {
                input = new FileStream(file_input, FileMode.Open, FileAccess.Read);
                br = new BinaryReader(input);
                output = new FileStream(file_output, FileMode.Create, FileAccess.Write);
                bw = new BinaryWriter(output);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return;
            }
            ////
            try
            {
                while ((block = br.ReadBytes(8)).Length > 0)
                {
                    BitArray encrypted_message = Utils.makeMessage(napraw(block));
                    bw.Write((encrypted_message.ToByteArray()));
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                input.Close();
                output.Close();
                br.Close();
                bw.Close();
            }
            finally
            {
                input.Close();
                output.Close();
                br.Close();
                bw.Close();
            }
        }
开发者ID:WPiotr,项目名称:BSK,代码行数:48,代码来源:Utils.cs

示例8: WriteFile

		public void WriteFile(string file)
		{
			BinaryWriter bw = new BinaryWriter(File.OpenWrite(file));
			WriteFile(bw);
			bw.Flush();
			bw.Close();
		}	
开发者ID:pmprog,项目名称:OpenXCOM.Tools,代码行数:7,代码来源:MpkFile.cs

示例9: OnDownloadComplete

        private void OnDownloadComplete(object sender, DownloadDataCompletedEventArgs e)
        {
            try
            {

                if (!e.Cancelled)
                {
                    while (File.Exists(Destination))
                    {
                        string[] temp = Destination.Split('.');
                        Destination = temp[0] + "_." + temp[1];
                    }
                    BinaryWriter bw = new BinaryWriter(new FileStream(Destination, FileMode.CreateNew));
                    bw.Write(e.Result);
                    bw.Close();
                }
                CallProcess(new ExcutionResult(ResultFlag.Result, "", "Download complete :\r\n" + Destination));
                DownloadCmdList.Remove(this);
            }catch(Exception ex)
            {
                CallProcess(new ExcutionResult(ResultFlag.Error, "", "Download Error :\r\n" + ex.ToString()));
                DownloadCmdList.Remove(this);

            }
        }
开发者ID:charuwat,项目名称:code,代码行数:25,代码来源:DownloadCommand.cs

示例10: Save

        public static void Save(Player player)
        {
            if (player == null)
            {
                logger.Error("Failed to save Player because no Player exists.");
                return;
            }

            string name = player.Name;
            if (name == null)
            {
                logger.Warn("Player has no name. Using name Anonymous as a fallback. Player cannot be guaranteed to have been saved properly.");
                name = "Anonymous";
            }
            string tempFile = name + ".dat";
            using(FileStream stream = new FileStream(tempFile, FileMode.Create))
            using (BinaryWriter writer = new BinaryWriter(stream))
            {
                try
                {
                    PlayerUnloader.unload(player, writer);
                }
                finally
                {
                    stream.Close();
                    writer.Close();
                }

            }

            string targetFile = name + ".plr";
            Encrypt(tempFile, targetFile);
            File.Delete(tempFile);
        }
开发者ID:roddy,项目名称:TEdit,代码行数:34,代码来源:PlrWriter.cs

示例11: DoAcceptTcpClientCallback

        public static void DoAcceptTcpClientCallback(IAsyncResult ar)
        {
            Thread.Sleep(0);
            Byte[] bytes = new Byte[1024];
            String data = null;
            TcpListener listener = (TcpListener)ar.AsyncState;
            TcpClient client = listener.EndAcceptTcpClient(ar);
            Console.WriteLine("Client connect completed");

            data = null;
            NetworkStream stream = client.GetStream();

            BinaryFormatter outformat = new BinaryFormatter();

            string name;
            name = outformat.Deserialize(stream).ToString();
            FileStream fs = new FileStream("D:\\" + name, FileMode.OpenOrCreate);
            BinaryWriter bw = new BinaryWriter(fs);
            int count;
            count = int.Parse(outformat.Deserialize(stream).ToString());
            int i = 0;
            for (; i < count; i += 1024)
            {

                byte[] buf = (byte[])(outformat.Deserialize(stream));
                bw.Write(buf);
            }
            Console.WriteLine("Successfully read in D:\\" + name);
            bw.Close();
            fs.Close();
            tcpClientConnected.Set();
        }
开发者ID:sbst,项目名称:code,代码行数:32,代码来源:Program.cs

示例12: Encode

        //����Voiceage��˾-G.729����
        public unsafe byte[] Encode(byte[] data)
        {
            MemoryStream src=new MemoryStream(data);
            System.IO.BinaryReader brsrc=new BinaryReader(src);
            MemoryStream dst=new MemoryStream();
            System.IO.BinaryWriter bwdst=new BinaryWriter(dst);
            int step=(int)(data.Length/160);
            for(int i=0;i<step;i++)
            {
                byte[] d=new byte[10];
                for(int k=0;k<d.Length;k++)
                {
                    d[k]=1;
                }
                byte[] o=brsrc.ReadBytes(160);
                va_g729a_encoder(o,d);

                bwdst.Write(d);
            }
            byte[] ret=dst.GetBuffer();
            brsrc.Close();
            bwdst.Close();
            src.Close();
            dst.Close();
            return ret;
        }
开发者ID:songques,项目名称:CSSIM_Solution,代码行数:27,代码来源:G972.cs

示例13: Page_Load

        protected void Page_Load(object sender, EventArgs e)
        {
            if (HttpContext.Current.Session["condominio"] != null)
            {
                if (Request.QueryString["id"] != null)
                {
                    var idDocumento = Request.QueryString["id"].Trim();
                    var fileName = "documenti/" + idDocumento + ".pdf";

                    if(!File.Exists(Request.PhysicalApplicationPath + fileName))
                    {
                        var service = new SferaService();
                        var info = new UserInfo(0, 1);
                        var documento = service.GetDocumentoByIdentificativo(idDocumento, info);
                        var docInfo = service.GetDocument(documento.ID, TipoDocumentoArchiviazione.FatturaPassiva, info);

                        var fs = File.Create(Request.PhysicalApplicationPath + fileName);
                        var writer = new BinaryWriter(fs);
                        writer.Write(docInfo.Body);
                        writer.Close();
                        fs.Close();
                        fs.Dispose();
                    }

                    documentFrame.Attributes.Add("src", fileName);
                }
            }
        }
开发者ID:gipasoft,项目名称:Sfera,代码行数:28,代码来源:loadDocumentoFrame.aspx.cs

示例14: AsyncUpload1_FileUploaded

        protected void AsyncUpload1_FileUploaded(object sender, FileUploadedEventArgs e)
        {
            byte[] imageData;
            using (Stream stream = e.File.InputStream)
            {
                imageData = new byte[stream.Length];
                stream.Read(imageData, 0, (int)stream.Length);
            }

            //save image

            string file = Server.MapPath("/Files/Verification/") + "\\" + e.File.FileName;
            //AsyncUpload1.UploadedFiles[0].SaveAs(file);

            string fullurl = Request.Url.AbsoluteUri;
            //string saveimgurl = //fullurl.Substring(0, fullurl.ToLower().IndexOf("order_form2.aspx")) + Thumbnail.ImageUrl.Replace("~/", "");

            //sitetemp.savepicurl2(saveimgurl, file);

            FileStream fs = new FileStream(file, FileMode.Create);
            BinaryWriter w = new BinaryWriter(fs);
            try
            {
                w.Write(imageData);
            }
            finally
            {
                fs.Close();
                w.Close();
            }
        }
开发者ID:Lornestar,项目名称:pfx,代码行数:31,代码来源:Radasyncupload.aspx.cs

示例15: SaveStreamToFile

        public static void SaveStreamToFile(Stream FromStream, string TargetFile)
        {
            // FromStream=the stream we wanna save to a file 
            //TargetFile = name&path of file to be created to save to 
            //i.e"c:\mysong.mp3" 
            try
            {
                //Creat a file to save to
                Stream ToStream = File.Create(TargetFile);

                //use the binary reader & writer because
                //they can work with all formats
                //i.e images, text files ,avi,mp3..
                BinaryReader br = new BinaryReader(FromStream);
                BinaryWriter bw = new BinaryWriter(ToStream);

                //copy data from the FromStream to the outStream
                //convert from long to int 
                bw.Write(br.ReadBytes((int)FromStream.Length));
                //save
                bw.Flush();
                //clean up 
                bw.Close();
                br.Close();
            }

             //use Exception e as it can handle any exception 
            catch (Exception e)
            {
                //code if u like 
            }
        }
开发者ID:uwitec,项目名称:web-mvc-logistics,代码行数:32,代码来源:Stream.cs


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