读取 .dat格式的文件(是关于证券方面的),16进制,第一次做到这个东西,不知道该如何下手,帮忙(急、重谢)用C#读取这种文件具体有两个案例(好像是dephi,不知道什么意思)地址是:
1、http://blog.5ilily.cn/article.asp?id=1687
2、http://www.pinggu.name/html/2008-3/19/298051.html 有人处理过这种事情,帮帮忙啊

解决方案 »

  1.   

    读取字节文件,用字节流.
    整个拷贝一下MSDN:
    using System;
    using System.IO;
    using System.Security.Permissions;class Test
    {
        static void Main()
        {
            // Load application settings.
            AppSettings appSettings = new AppSettings();
            Console.WriteLine("App settings.\nAspect Ratio: {0}, " +
                "Lookup directory: {1},\nAuto save time: {2} minutes, " +
                "Show status bar: {3}\n",
                new Object[4]{appSettings.AspectRatio.ToString(),
                appSettings.LookupDir, appSettings.AutoSaveTime.ToString(),
                appSettings.ShowStatusBar.ToString()});        // Change the settings.
            appSettings.AspectRatio   = 1.250F;
            appSettings.LookupDir     = @"C:\Temp";
            appSettings.AutoSaveTime  = 10;
            appSettings.ShowStatusBar = true;        // Save the new settings.
            appSettings.Close();
        }
    }// Store and retrieve application settings.
    class AppSettings
    {
        const string fileName = "AppSettings#@@#.dat";
        float  aspectRatio;
        string lookupDir;
        int    autoSaveTime;
        bool   showStatusBar;    public float AspectRatio
        {
            get{ return aspectRatio; }
            set{ aspectRatio = value; }
        }    public string LookupDir
        {
            get{ return lookupDir; }
            set{ lookupDir = value; }
        }    public int AutoSaveTime
        {
            get{ return autoSaveTime; }
            set{ autoSaveTime = value; }
        }    public bool ShowStatusBar
        {
            get{ return showStatusBar; }
            set{ showStatusBar = value; }
        }    public AppSettings()
        {
            // Create default application settings.
            aspectRatio   = 1.3333F;
            lookupDir     = @"C:\AppDirectory";
            autoSaveTime  = 30;
            showStatusBar = false;        if(File.Exists(fileName))
            {
                BinaryReader binReader =
                    new BinaryReader(File.Open(fileName, FileMode.Open));
                try
                {
                    // If the file is not empty,
                    // read the application settings.
                    // Read 4 bytes into a buffer to
                    // determine if the file is empty.
                    byte[] testArray = new byte[3];
                    int count = binReader.Read(testArray, 0, 3);                if (count != 0)
                    {
                        aspectRatio   = binReader.ReadSingle();
                        lookupDir     = binReader.ReadString();
                        autoSaveTime  = binReader.ReadInt32();
                        showStatusBar = binReader.ReadBoolean();
                    }
                }            // If the end of the stream is reached before reading
                // the four data values, ignore the error and use the
                // default settings for the remaining values.
                catch(EndOfStreamException e)
                {
                    Console.WriteLine("{0} caught and ignored. " +
                        "Using default values.", e.GetType().Name);
                }
                finally
                {
                    binReader.Close();
                }
            }    }    // Create a file and store the application settings.
        public void Close()
        {
            using(BinaryWriter binWriter =
                new BinaryWriter(File.Open(fileName, FileMode.Create)))
            {
                binWriter.Write(aspectRatio);
                binWriter.Write(lookupDir);
                binWriter.Write(autoSaveTime);
                binWriter.Write(showStatusBar);
            }
        }
    }