C# 里如何把一个byte[] 追加到另一个大byte[] 里?

天-笑 2014-04-05 10:25:29
C# 里如何把一个byte[] 追加到另一个大byte[] 里?
...全文
13145 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
six-years 2014-04-08
  • 打赏
  • 举报
回复
追加不可以 把小的byte[]替换大的byte[]指定位置是可以的
hanhualangzi 2014-04-07
  • 打赏
  • 举报
回复
直接用List<byte>呗.
javaoraspx 2014-04-07
  • 打赏
  • 举报
回复
Buffer
skyworth98 2014-04-07
  • 打赏
  • 举报
回复
引用 3 楼 BenBenBears 的回复:
Array.CopyTo / stream.Write/List<byte> 均能实现将Old Array 复制到 New Array 。因为当创建了数组实例时,将建立维度数和每个维度的长度。 在实例的生存期内,这些值不能更改,所以只能复制到新的数组。
sp 数组是没办法追加的,建议使用List
BenBenBears 2014-04-05
  • 打赏
  • 举报
回复
Array.CopyTo / stream.Write/List<byte> 均能实现将Old Array 复制到 New Array 。因为当创建了数组实例时,将建立维度数和每个维度的长度。 在实例的生存期内,这些值不能更改,所以只能复制到新的数组。
m777 2014-04-05
  • 打赏
  • 举报
回复
试试看看 ,没有测试,自己试试修改一下吧! private byte[] CopyToBig(byte[] bBig,byte[] bSmall) { List<byte> lTemp = new List<byte>(); lTemp.AddRange(bBig); lTemp.AddRange(bSmall); bBig = new byte[lTemp.Count]; lTemp.CopyTo(bBig); return bBig; }
tcmakebest 2014-04-05
  • 打赏
  • 举报
回复
数据是无法追加的,只能重新生成,再分别复制到指定位置。
本拉灯 2014-04-05
  • 打赏
  • 举报
回复
private byte[] CopyToBig(byte[] bBig,byte[] bSmall) { byte[] tmp= new byte[bBig.Length+bSmall.Length]; System.Buffer.BlockCopy(bBig,0,tmp,0,bBig.Length); System.Buffer.BlockCopy(bSmall,0,tmp,bBig.Length,bSmall.Length); return tmp; }
lorl2 2014-04-05
  • 打赏
  • 举报
回复
static class Program
    {
        /// <summary>
        /// 应用程序的主入口点。
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();

            ByteArray aa = new ByteArray(new byte[50]);
            ByteArray bb = new ByteArray(new byte[100]);

            ByteArray cc = aa + bb;
            byte[] xxoo = cc.getBytes();
            for (int i = 0; i < xxoo.Length; i++)
            {
                Console.WriteLine(xxoo[i].ToString());
            }
            Console.ReadLine();
        }

        class ByteArray
        {
            private byte[] m_data = null;
            public ByteArray(byte[] data)
            {
                m_data = data;
            }
            public byte[] getBytes()
            {
                return m_data;
            }
            static public ByteArray operator +(ByteArray a, ByteArray b)
            {
                byte[] xxoo1 = a.getBytes();
                byte[] xxoo2 = b.getBytes();
                using (System.IO.MemoryStream ms = new System.IO.MemoryStream())
                {
                    ms.Write(xxoo1, 0, xxoo1.Length);
                    ms.Write(xxoo2, 0, xxoo2.Length);
                    return new ByteArray(ms.ToArray());
                }
            }
        }

    }
检测指定目录是否存在, 检测指定文件是否存在, 如果存在则返回true, 获取指定目录中所有文件列表,获取指定目录中所有子目录列表, 取指定目录及子目录中所有文件列表, 指定目录的绝对路径,检测指定目录是否为空, 检测指定目录中是否存在指定的文件, 若要搜索子目录请使用重载方法., 检测指定目录中是否存在指定的文件, 创建目录, 删除目录, 创建文件, 移动文件(剪贴--粘贴), 复制文件, 根据时间得到目录名 / 格式:yyyyMMdd 或者 HHmmssff, 根据时间得到文件名HHmmssff, 根据时间获取指定路径的 后缀名的 的所有文件, 复制文件夹,检查文件, 如果文件不存在则创建, 删除指定文件夹对应其他文件夹的文件, 从文件的绝对路径中获取文件名( 包含扩展名 ), 复制文件参考方法,页面中引用, 创建一个目录, 创建一个文件, 并将字节流写入文件, 获取文本文件的行数, 获取一个文件的长度, 单位为Byte, 获取文件大小并以B,KB,GB,TB, 获取指定目录中的子目录列表, 向文本文件写入内容, 向文本文件的尾部追加内容, 将现有文件的内容复制到新文件中, 将文件移动到指定目录, 从文件的绝对路径中获取文件名( 不包含扩展名 ), 从文件的绝对路径中获取扩展名 以上每一行为一个方法, 例子如下: #region 清空指定目录 /// /// 清空指定目录下所有文件及子目录,但该目录依然保存. /// /// 指定目录的绝对路径 public static void ClearDirectory(string directoryPath) { directoryPath = HttpContext.Current.Server.MapPath(directoryPath); if (IsExistDirectory(directoryPath)) { //删除目录中所有的文件 string[] fileNames = GetFileNames(directoryPath); for (int i = 0; i < fileNames.Length; i++) { DeleteFile(fileNames[i]); } //删除目录中所有的子目录 string[] directoryNames = GetDirectories(directoryPath); for (int i = 0; i < directoryNames.Length; i++) { DeleteDirectory(directoryNames[i]); } } } #endregion #region 清空文件内容 /// /// 清空文件内容 /// /// 文件的绝对路径 public static void ClearFile(string filePath) { //删除文件 File.Delete(filePath); //重新创建该文件 CreateFile(filePath); } #endregion #region 删除指定目录 /// /// 删除指定目录及其所有子目录 /// /// 指定

110,533

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧