我是C#的初学者,我想知道如何用C# C
static void example(const char *filename)
{
FILE *f;
outbuf_size = 10000;
outbuf = malloc(outbuf_size);
f = fopen(filename, "wb");
if (!f) {
fprintf(stderr, "could not open %s\n", filename);
exit(1);
}
fwrite(outbuf, 1, outbuf_size, f);
fclose(f);
}请帮帮我。
顺便说一句:我正在尝试移植FFMPEG api-使用Tao.FFMpeg表示的here示例(Tao是围绕C#的.Net包装器..旧的和和FFMPEG中完全一样的sintax )所以你能读一读这篇文章并告诉我在我的代码样本中遗漏了什么……
我的问题是-我知道如何移植FFMpeg部件,但我只是不确定如何以适合.Net的方式移植文件IO部件\函数
发布于 2010-07-20 21:36:00
因为您提供的库的示例代码可以读取和写入二进制文件,所以我建议使用System.IO.BinaryReader和System.IO.BinaryWriter。
static void example(string filename)
{
StreamReader sr;
BinaryWriter bw;
try
{
sr = new StreamReader(filename);
bw = new BinaryWriter(File.Open("out.bin", FileMode.Create));
bw.Write(sr.ReadToEnd());
bw.Flush();
bw.Close();
sr.Close();
}
catch(Exception ex)
{
// Handle the exception
}
}发布于 2010-07-17 22:07:32
我不会为您编写所有代码,而是直接转到System.IO.File。
发布于 2010-07-17 22:16:12
您的代码示例令人困惑。你的意思是把一些有意义的东西放在缓冲区中并写到文件中,或者你的意思是从文件中读取到缓冲区中。
using System.IO;
byte[] bytesFromFile = File.ReadAllBytes(filePath);
byte[] someBytes = new byte[someLength];
// omitted: put some values into someBytes array
File.WriteAllBytes(filePath, someBytes);https://stackoverflow.com/questions/3271780
复制相似问题