简体   繁体   English

在Windows Mobile中读取和写入文件中的所有字节

[英]Read and Write all bytes of/in a file in Windows Mobile

I need to read all bytes of a file and write this byte array to another file. 我需要读取文件的所有字节并将此字节数组写入另一个文件。 Ie I need the same behavior of File.ReadAllBytes and File.WriteAllBytes in Windows Mobile 6.1. 即我需要Windows Mobile 6.1中的File.ReadAllBytesFile.WriteAllBytes的相同行为。

What is the fastest method to do this work? 做这项工作的最快方法是什么?

Do you actually need the whole file in memory at any time? 你真的需要内存中的整个文件吗? If not, I'd just use something like: 如果没有,我会使用类似的东西:

public static void CopyStream(Stream input, Stream output)
{
    byte[] buffer = new byte[32 * 1024]; // Or whatever size you want
    int read;
    while ((read = input.Read(buffer, 0, buffer.Length)) > 0)
    {
        output.Write(buffer, 0, read);
    }
}

Then just open each file accordingly: 然后相应地打开每个文件:

using (Stream input = File.OpenRead(...), output = File.OpenWrite(...))
{
    CopyStream(input, output);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM