Пример #1
0
 public static byte[] ReadFile(string fullpath)
 {
     byte[] buffer = null;
     if (File.Exists(fullpath))
     {
         FileStream fs = null;
         try
         {
             fs     = new FileStream(fullpath, FileMode.Open, FileAccess.Read);
             buffer = new byte[fs.Length];
             fs.Read(buffer, 0, buffer.Length);
         }
         catch (Exception e)
         {
             LDebugger.LogError(LOG_TAG, "ReadFile() Path:{0}, Error:{1}", fullpath, e.Message);
         }
         finally
         {
             if (fs != null)
             {
                 fs.Close();
             }
         }
     }
     else
     {
         LDebugger.LogError(LOG_TAG, "ReadFile() File is Not Exist: {0}", fullpath);
     }
     return(buffer);
 }
Пример #2
0
        // Use this for initialization
        void Start()
        {
            UserInfo userInfo = new UserInfo();

            userInfo.id    = 0;
            userInfo.name  = "Allenzwli";
            userInfo.title = "testNotPBMember";

            byte[] buff = PBSerializer.NSerialize(userInfo);

            var info = PBSerializer.NDeserialize <UserInfo>(buff);

            LDebugger.Log(this.GetType().ToString(), " id: {0} ; name: {1}; title:{2};", info.id, info.name, info.title);
        }
Пример #3
0
        public static int SaveFile(string fullpath, byte[] content)
        {
            if (content == null)
            {
                content = new byte[0];
            }

            string dir = PathUtils.GetParentDir(fullpath);

            if (!Directory.Exists(dir))
            {
                try
                {
                    Directory.CreateDirectory(dir);
                }
                catch (Exception e)
                {
                    LDebugger.LogError(LOG_TAG, "SaveFile() CreateDirectory Error! Dir:{0}, Error:{1}", dir, e.Message);
                    return(-1);
                }
            }

            FileStream fs = null;

            try
            {
                fs = new FileStream(fullpath, FileMode.Create, FileAccess.Write);
                fs.Write(content, 0, content.Length);
            }
            catch (Exception e)
            {
                LDebugger.LogError(LOG_TAG, "SaveFile() Path:{0}, Error:{1}", fullpath, e.Message);
                fs.Close();
                return(-1);
            }

            fs.Close();
            return(content.Length);
        }