帮助C#.使用文件流编辑文件. [英] Help C#. Editing file using filestream.

查看:95
本文介绍了帮助C#.使用文件流编辑文件.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,这是我的第一篇文章.我来自阿根廷,所以我会尽力做到最好的英语.

我需要以下问题的帮助.我使用NetworkStream从客户端应用程序接收到服务器应用程序的文件.收到文件后,我将其临时保存到名为"temp"的硬盘中.接收成功,每个字节都被完美接收.
我用来发送文件的协议是(不带"):"FileName | FileSize | FileContent"
现在,我需要组成最终文件,即原始文件.我可以使用FileStream创建一个新文件,其名称在temp文件中,并且可以读取其大小,但是我不知道如何在新文件中仅写入"temp" FileContent.

Hello everyone, this is my first post. I am from Argentina, so I''ll try to do the best out of my english.

I need help with the following issue. I receive a file from a client application to a server application using NetworkStream. As I receive the file, I save it temporarily to disc in a dile called "temp". The recepcion is succesfull, every byte is receive perfectly.
The protocol I used to send the file is (without "): "FileName|FileSize|FileContent"
Now I need to make up the final file, the original. I can create a new file using FileStream with the name receive in the temp file, as well as I can read its size, but I don''t know how to write only the "temp" FileContent in the new file. Is there any simple way to exclude the FileName and FileSize?

推荐答案

请参考此链接....

VB.NET中的文件处理和序列化 [如何将二进制数据存储和提取到文件流列中 [在没有临时文件或内存缓冲区的情况下,将文本插入C#中的现有文件中 [
Please Refer this links....

File Handling and Serialization in VB.NET[^]

How to store and fetch binary data into a file stream column[^]

Insert Text into Existing Files in C#, Without Temp Files or Memory Buffers[^]


感谢您的回答.
我通过以下方式解决了该问题:接收并存储了临时文件后,我将1024个字节读取到缓冲区中,然后将其转换为字符串,然后使用string.spit(''|'')将名称和文件大小分隔为不同的变量.之后,使用file.seek将红色指针定位到"FileSize |"之后的第一个字节并将所有读数保存到新的最终文件中.

我已阅读了您推荐的文章.顺便说一句很有趣.
能够在读取临时文件的FileName | FileSize字节后将它们删除,然后将临时文件重命名为原始文件,这将是很棒的.我没有找到该怎么做的方法,也没有找到可行的方法.
谢谢!!
Thanks for answering.
I resolve the issue in the following way: After receiving and storing the temp file, I read 1024 bytes to a buffer which I convert to string, then with string.spit(''|'') I separate the name and file size in different variables. After it, with file.seek I positioned the reding pointer to the first byte after "FileSize|" and save all the readings to a new final file.

I have read the articles you recomend. Very interesting by the way.
It would be great to be able to remove the FileName|FileSize bytes of the temporary file after reading them, and then just rename the temp file to become the original file. I didn''t find how to do this, nor if it is posible.
Thanks!!


这篇关于帮助C#.使用文件流编辑文件.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆