簡體   English   中英

在Windows Mobile中讀取和寫入文件中的所有字節

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

我需要讀取文件的所有字節並將此字節數組寫入另一個文件。 即我需要Windows Mobile 6.1中的File.ReadAllBytesFile.WriteAllBytes的相同行為。

做這項工作的最快方法是什么?

你真的需要內存中的整個文件嗎? 如果沒有,我會使用類似的東西:

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);
    }
}

然后相應地打開每個文件:

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