使用c#将几个不同的文件合并到一个文件中 [英] merge several different files into a single file using c#

查看:104
本文介绍了使用c#将几个不同的文件合并到一个文件中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要将多个文件(视频和音乐和文本)合并到一个文件中,并使用自定义文件类型(例如:* .abcd)和自定义文件数据结构,该文件只能由我的程序和我的程序读取程序应该能够分离这个文件的各个部分。在.net&c#中如何做到这一点? - 我的文件有任何大小,例如300 MB,500 MB或1 GB,合并文件的大小约为1.5或2 GB,我怎么做? ..(使用流或内存流?!!)







https:// www。 imageupload.co.uk/image/ZWnh



我的程序类似于Microsoft Power Point。在pptx文件中,您可以放置​​文本和视频,然后保存文件* .pptx格式并随时加载..

解决方案

您好b $ b

我很可能会使用zip存档它会给你很多开箱即用的东西,这甚至是微软格式的构建方式。尝试将word文件(.docx)重命名为(.zip)并解压缩它,你会看到。



尝试以下文章我只是用Google搜索

http:// www .tugberkugurlu.com / archive / net-4-5-to-support-zip-file-manipulation-of-the-box [ ^ ]



另一种选择是创建自己的格式,这将更多的工作,但不一定复杂。

你开始写一个包含有关文件的信息的标题名称和大小,然后你在此之后汇编文件。这绝对应该在二进制级别上完成,而不是使用XML或Json之类的任何激励格式或者你能想出的任何格式。



标题看起来像,使用文件名中不接受的一些令牌,如[]

[int32包含nr文件]

[filename1] [size1 as int64 8 bytes]

[filename2] [size2 as int64 8 bytes]

[filename3] [size3 as int64 8 bytes]

[filename4] [size4 as int64 8 bytes]



在您刚刚汇总文件的标题之后,因为您知道每个文件的文件大小应该很容易在以后提取


< blockquote>我建​​议你把它们放在一个ZIP文件中(必要时带密码) - SharpZipLib [ ^ ]非常好,或者这里有很多文章:< a href =https://www.googl e.co.uk/search?newwindow=1&safe=off&es_sm=93&q=compression+demo+site:codeproject.com&spell=1&sa=X&ved=0CBsQBSgAahUKEwjt25rjz4_GAhWHMdsKHf4-ABA&biw=1080& bih = 1761> Google [ ^ ]


I need to combine multiple files (video & music & text) into single file with a custom file type (for example: *.abcd) and custom file data structure , and the file should only be read by my program and my program should be able to separate parts of this file. How do this in .net & c#? -- my file has any size , for example 300 MB , 500 MB or 1 GB and merged file's size is about 1.5 or 2 GB , how i do it ? .. (using stream or memory stream ?!!)



https://www.imageupload.co.uk/image/ZWnh

My program is similar to Microsoft Power Point .in pptx file you can put your texts and videos and then save the file with *.pptx format and load it anytime..

解决方案

Hi
I would most likely use a zip archive for this it will give you a lot of things out of the box, this is even how microsoft formats are beeing built. Try renaming a word file (.docx) to a (.zip) and decompress it and you will see.

Try following article I just googled
http://www.tugberkugurlu.com/archive/net-4-5-to-support-zip-file-manipulation-out-of-the-box[^]

Another option would be to create your own format which will be more work but not necessarily complicated.
you start with writing a header which contains information about the files like name and size and then you concatinate the files after this. This should definetly be done on a binary level and not make use of any excisting formats like XML or Json or whatever you can come up with.

Header could look like, use some token that is not accepted in a filename like []
[int32 containing nr Of files]
[filename1][size1 as int64 8 bytes]
[filename2][size2 as int64 8 bytes]
[filename3][size3 as int64 8 bytes]
[filename4][size4 as int64 8 bytes]

after the header you just concatinate the files since you know the file size of each file is should be easy to extract them later


I'd suggest you look at putting them in a ZIP file (With a password if necessary) - SharpZipLib[^] is pretty good, or there are loads of articles here on the subject: Google[^]


这篇关于使用c#将几个不同的文件合并到一个文件中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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