본문 바로가기
다물칸 주소복사
조회 수 76 추천 수 0 댓글 0
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
Extra Form
구분 팁&트릭
출처 http://stackoverflow.com/questions/6397235/write-bytes-to-file

안녕하세요. 엔조이데브 쥔장입니다.

무더운 날씨 어떻게 보내시나요? 그런데 사무실은 너무 춥다는 ㅡㅡ;

요즘 blob저장해서 가져오는거 하고 있는데 mysqlDataReader로 가져온 바이트배열 데이터를 파일로 저장하는 함수 입니다.

 

        public static bool ByteArrayToFile(string _FileName, byte[] _ByteArray)
        {
            try
            {
                // Open file for reading
                FileStream _FileStream =
                   new FileStream(_FileName, FileMode.Create, FileAccess.Write);
                // Writes a block of bytes to this stream using data from
                // a byte array.
                _FileStream.Write(_ByteArray, 0, _ByteArray.Length);

                // close file stream
                _FileStream.Close();

                return true;
            }
            catch (Exception _Exception)
            {
                // Error
                Console.WriteLine("Exception caught in process: {0}",
                                  _Exception.ToString());
            }

            // error occured, return false
            return false;
        }