IT博客汇
  • 首页
  • 精华
  • 技术
  • 设计
  • 资讯
  • 扯淡
  • 权利声明
  • 登录 注册

    Unity在非PC平台提示找不到某些IO函数的解决

    yoyo发表于 2015-06-12 02:31:00
    love 0

    unity5在为ios打包资源的时候,提示:

     error CS0117: `System.IO.File' does not contain a definition for `WriteAllBytes'
    

    很奇怪的问题,后来自己写了读写函数,解决!

        /// 
        /// 擦写文件(用于替换系统File的同名静态方法)
        /// 
        /// 
        /// 
        /// 
        /// 
        public static void WriteAllBytes(string file,byte[] data,int offset = 0,int length = -1)
        {
            if (length == -1) length = data.Length - offset;
            FileStream fs = new FileStream(file, FileMode.Create);
            BinaryWriter w = new BinaryWriter(fs);
            w.Write(data,offset,length);
            w.Flush();
            w.Close();
            fs.Close();
        }
    
        /// 
        /// 读取文件(用于替换系统File的同名静态方法)
        /// 
        /// 
        /// 
        /// 
        public static byte[] ReadAllBytes(string file)
        {
            FileStream fs = new FileStream(file, FileMode.Open);
            BinaryReader r = new BinaryReader(fs);
            byte[] data = r.ReadBytes((int)fs.Length);
            r.Close();
            fs.Close();
            return data;
        }
    


沪ICP备19023445号-2号
友情链接