将二进制文件2附加到二进制文件1? [英] Append binary file 2 to binary file 1?

查看:104
本文介绍了将二进制文件2附加到二进制文件1?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问候,


这看起来应该很简单,但我不知道该怎么做。


我只想将二进制文件2附加到二进制文件1的末尾。


请提供示例代码?


谢谢!


-

- = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = -

获得免费软件,学习东西,赚钱。
http://www.vbmark.com

- = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = -

Greetings,

This seems like it should be simple but I can''t figure out how to do this.

I just want to append binary file 2 on to the end of binary file 1.

Sample code please?

Thanks!

--
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Get freeware, learn things, make money.
http://www.vbmark.com
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

推荐答案

vbMark< no@email.com>写道:
vbMark <no@email.com> wrote:
这似乎应该很简单,但我不知道如何做到这一点。

我只想将二进制文件2追加到最后二进制文件1.

请看示例代码?
This seems like it should be simple but I can''t figure out how to do this.

I just want to append binary file 2 on to the end of binary file 1.

Sample code please?




打开一个FileStream到你要追加的文件,使用

FileMode.Append,并使用FileMode.Open打开另一个要添加到

结尾的文件。


分配一个缓冲,比方说,32K,并重复读取第二个

流进入缓冲区并写入第一个流但是很多数据

你读了。


http://www.pobox .com / ~sipet / csharp / readbinary.html 示例代码

从缓冲区读取。


别忘了使用使用"处理你的溪流的声明甚至如果抛出异常则需要



-

Jon Skeet - < sk ** *@pobox.com>
http://www.pobox.com/~双向飞碟

如果回复小组,请不要给我发邮件



Open one FileStream to the file you wish to append to, using
FileMode.Append, and open another one to the file you wish to add to
the end, using FileMode.Open.

Allocate a buffer of, say, 32K, and repeatedly Read from the second
stream into the buffer and Write to the first stream however much data
you read.

See http://www.pobox.com/~skeet/csharp/readbinary.html for sample code
reading from buffers.

Don''t forget to use "using" statements to dispose of your streams even
if exceptions are thrown.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too


我该怎么称呼这个名为Factorial_的函数示例代码:


class SomeClass {


...

public int Factorial(int f){

如果(f <0)抛出SomeException(Some message。);

if(f == 0 || f == 1)返回1;

返回Factorial_(f);

}


private int Factorial_(int f){

如果(f == 1)返回1;

返回f * Factorial_(f-1);

}

...

}


调用它Factorial_看起来很糟糕。无法调用Factorial,因为它是公共方法应该具有的

名称。它应该是什么?


telmo
What should i call the functions named Factorial_ in this sample code:

class SomeClass {

...
public int Factorial(int f) {
if (f<0) throw SomeException("Some message.");
if (f==0 || f==1) return 1;
return Factorial_(f);
}

private int Factorial_(int f) {
if (f==1) return 1;
return f*Factorial_(f-1);
}
...
}

Calling it Factorial_ looks bad. Cannot call Factorial because it is the
name that the public method should have. What should it be?

telmo


你好vbMark,

试试这个:


FileStream fs = new FileStream(" c:\\somefile.abc",FileMode.Append);

BinaryWriter br = new BinaryWriter(fs);


这将允许您附加到现有文件,或者如果文件没有

存在,将创建一个新文件。所以你可以打开你的一个文件并使用上面的代码将它写入另一个二进制文件。


希望有帮助

Mark R Dawson


" vbMark"写道:
Hi vbMark,
try this:

FileStream fs = new FileStream("c:\\somefile.abc", FileMode.Append);
BinaryWriter br = new BinaryWriter(fs);

This will allow you to append to existing files, or if the file does not
exist a new one will be created. So you can open one of your files and write
it onto the other binary file using the code from above.

Hope that helps
Mark R Dawson

"vbMark" wrote:
问候,

这看起来应该很简单,但我不知道该怎么做。

示例代码好吗?

谢谢!

- -
- = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = -
获得免费软件,学习东西,赚钱。
http://www.vbmark.com
- = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = -
Greetings,

This seems like it should be simple but I can''t figure out how to do this.

I just want to append binary file 2 on to the end of binary file 1.

Sample code please?

Thanks!

--
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Get freeware, learn things, make money.
http://www.vbmark.com
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-



这篇关于将二进制文件2附加到二进制文件1?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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