首页 新闻 会员 周边 捐助

如何改变文件格式

0
悬赏园豆:5 [已关闭问题] 关闭于 2012-02-22 11:03

问题背景:

将手机通讯录备份,压缩RAR,将后缀名改为.jpg,上传至QQ相册,但是提示格式错误,以前好像QQ空间只检查后缀名,咋又检查文件格式了,不晓得怎样处理了,大神们帮帮忙~

另外,当以后需要的时候 如何下载并还原为RAR文件格式~

c#
子夜一梦的主页 子夜一梦 | 菜鸟二级 | 园豆:213
提问于:2012-02-22 09:50
< >
分享
所有回答(1)
0

        private static void Change()
        {
            System.IO.FileStream fs = new System.IO.FileStream(@"F:\C盘搬家\My Documents\Wandoujia\Backup\1.jpg", System.IO.FileMode.Open, System.IO.FileAccess.Read);
            System.IO.BinaryReader r = new System.IO.BinaryReader(fs);

            System.IO.FileStream fs2 = new System.IO.FileStream(@"F:\C盘搬家\My Documents\Wandoujia\Backup\Backup.rar", System.IO.FileMode.Open, System.IO.FileAccess.Read);
            System.IO.BinaryReader r2 = new System.IO.BinaryReader(fs2);

            byte[] newfile = new byte[fs.Length + fs2.Length];
            //byte[] tempbyte = Encoding.Default.GetBytes("7173");
            //for (int i = 0; i < tempbyte.Length; i++)
            //{
            //    newfile[i] = tempbyte[i];
            //}
            //for (int i = tempbyte.Length; i < fs.Length; i++)
            //{
            //    newfile[i] = r.ReadByte();
            //}
            for (int i = 0; i < fs.Length; i++)
            {
                newfile[i] = r.ReadByte();
            }
            for (long i = fs.Length; i < fs.Length + fs2.Length; i++)
            {
                newfile[i] = r2.ReadByte();
            }
           

            FileStream fsout = new FileStream(@"F:\C盘搬家\My Documents\Wandoujia\Backup\Backup.jpg", System.IO.FileMode.Create, System.IO.FileAccess.Write);
            System.IO.BinaryWriter wr = new BinaryWriter(fsout);

            wr.Write(newfile, 0, newfile.Length);
            fsout.Flush();
            fsout.Close();
        }

 

将图片加在前面就行了啊~~ 哈哈 ~

子夜一梦 | 园豆:213 (菜鸟二级) | 2012-02-22 11:02
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册