1. 程式人生 > >unity 讀取位元組流

unity 讀取位元組流

        public  byte[] GetStreamBytes(string path)
        {
            try
            {
                FileStream stream = new FileInfo(path).OpenRead();
                byte[] buffer = new byte[stream.Length];
                //從流中讀取位元組塊並將該資料寫入給定緩衝區buffer中
                stream.Read(buffer, 0, System.Convert.ToInt32(stream.Length));
                stream.Close();
                stream.Dispose();
                return buffer;
            }
            catch (System.Exception ex)
            {
                Debug.Log(ex.Message);
            }
            return null;
        }