0

我有以下方法:

    public static byte[] ConvertFileToBytes(string filePath)
    {
        var fInfo = new FileInfo(filePath);
        var numBytes = fInfo.Length;
        var dLen = Convert.ToDouble(fInfo.Length / 1000000);

        var fStream = new FileStream(filePath, FileMode.Open, FileAccess.Read);
        var br = new BinaryReader(fStream);

        var data = br.ReadBytes((int)numBytes);
        br.Close();

        fStream.Close();
        fStream.Dispose();

        return data;
    }

    public static void ConvertBytesToFile(byte[] file, string filePath)
    {
        var ms = new MemoryStream(file);

        var fs = new FileStream(filePath, FileMode.Create);

        ms.WriteTo(fs);

        ms.Close();
        fs.Close();
        fs.Dispose();
    }

这些方法的正确名称是什么?(因为将XXX转换为YYY只是不会在实用程序库中剪切它)

4

5 回答 5

10

File.ReadAllBytesFile.WriteAllBytes怎么样;)

于 2009-04-26T21:28:23.910 回答
2

通常使用的术语是“序列化”和“反序列化”(或有时“编组”和“解组”)。

于 2009-04-26T21:29:55.063 回答
0

WriteAllBytes 和 ReadAllBytes 是一个很好的建议,但要回答您的问题...

Save() 将是重命名 ConvertToFile() 和 Object.CreateFromFile() 的一个不错的选择。

于 2009-04-27T00:12:43.690 回答
0

Marshalling/Unmarshalling 可能是合适的术语。

http://en.wikipedia.org/wiki/Marshalling_(computer_science)

于 2009-04-26T21:30:07.340 回答
0

在 C++ 中,它们被称为读写。

于 2009-04-26T21:31:38.367 回答