예제 #1
0
        public static string ShowString(string TextFileName)
        {
            BinaryReader binaryReader = null;
            FileStream   fileStream   = null;
            string       allLine      = null;

            try
            {
                fileStream   = new FileStream(TextFileName, FileMode.Open, FileAccess.Read, FileShare.None);
                binaryReader = new BinaryReader(fileStream);
                ShpHeader newShpHeader = new ShpHeader();//定义header
                newShpHeader = ShpFunction.ReadShpHeader(binaryReader);
                ShpFileBody newShpBody = new ShpFileBody();
                allLine = allLine + ShpFunction.ShpHeader_to_String(newShpHeader);
                //大端格式读出记录编号,长度
                while (binaryReader.BaseStream.Position < binaryReader.BaseStream.Length)
                {
                    newShpBody = ShpFunction.ReadShpFileBody(binaryReader);
                    allLine    = allLine + ShpFunction.ShpBody_to_String(newShpBody);
                }
                ShpFunction.CloseReader(binaryReader, fileStream);
            }

            catch (Exception ex)
            {
                Console.WriteLine("在读取文件的过程中,发生了异常!");
                Console.WriteLine(ex.Message);
                Console.WriteLine(ex.StackTrace);
            }
            finally
            {
                if (fileStream != null)
                {
                    try
                    {
                        fileStream.Close();
                    }
                    catch
                    {
                        // 最后关闭文件,无视关闭是否会发生错误了.
                    }
                }
            }
            return(allLine);
        }