C# File 文件操作

C# File 文件操作

文件转Byte[]

public static byte[] GetBytesByFile(string path)
        {
            if (!File.Exists(path))
                return null;
            byte[] data = null;
            using (FileStream fs_read = new FileStream(path, FileMode.Open, FileAccess.Read))
            {
                data = new byte[fs_read.Length];
                fs_read.Read(data, 0, data.Length);
            }
            return data;
        }

Byte转文件[]

public static void SaveFileFromBytes(byte[] data, string path)
        {
            if (data == null || data.Length == 0)
                return;
            using (FileStream fs_write = new FileStream(path, FileMode.Create, FileAccess.Write))
            {
                fs_write.Write(data, 0, data.Length);
            }
        }
上一篇:Unity3D直接从Zip中读取文本数据


下一篇:Python 浅谈编程规范和软件开发目录规范的重要性