当前位置: 首页>>代码示例>>C#>>正文


C# System.IO.FileStream.ReadByte方法代码示例

本文整理汇总了C#中System.IO.FileStream.ReadByte方法的典型用法代码示例。如果您正苦于以下问题:C# System.IO.FileStream.ReadByte方法的具体用法?C# System.IO.FileStream.ReadByte怎么用?C# System.IO.FileStream.ReadByte使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.IO.FileStream的用法示例。


在下文中一共展示了System.IO.FileStream.ReadByte方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Main

    static void Main()
    {
        string fn = "test";

         using ( System.IO.FileStream   fs = new System.IO.FileStream(fn, System.IO.FileMode.Open, System.IO.FileAccess.Read) )
         // using ( System.IO.BinaryReader br = new System.IO.BinaryReader(fs))
         {
           Say("Filesize:{0} bytes\nPos:{1}\n", fs.Length, fs.Position);

            byte [] bt = new byte[100];

            //while(true)
            if( bt[0] != fs.ReadByte() )
              break; //Say("EOF");
            else
              Say("{0}\n", bt[0]);

            //if ( bt[0] != fs.ReadByte() )
            //if (b != fs.ReadByte())

            //Say("{0}\n", bt);

          //SayFile(bw, "{0} - {1}\n", "Привет", "файл");

         }
    }
开发者ID:akmaplus,项目名称:My_sources_cs,代码行数:26,代码来源:read.cs

示例2: BackupReader

 public BackupReader(string path)
 {
         System.IO.FileStream fs = new System.IO.FileStream(path, System.IO.FileMode.Open, System.IO.FileAccess.Read);
         fs.ReadByte();
         inputStream = fs;
         inputStream.Seek(0, System.IO.SeekOrigin.Begin);
 }
开发者ID:solutema,项目名称:ultralight,代码行数:7,代码来源:BackupReader.cs

示例3: GetIndex

        /// <summary>
        /// This will return a copy of the index, but also preserve
        /// a master copy in this object that is read-only.
        /// </summary>
        /// <param name="filename">The filename of the dbf file to index</param>
        /// <returns>returns a List of long offsets.  The index in the list is the row value.</returns>
        public List<long> GetIndex(string filename)
        {
            List<long> OffsetsCopy = new List<long>();
            _offsets = new List<long>();
            if (filename == null)
            {
                throw new ArgumentNullException(filename);
            }
            // check for the file existing here, otherwise we will not get an error
            //until we read the first record or read the header.
            if (!System.IO.File.Exists(filename))
            {
                throw new System.IO.FileNotFoundException(String.Format("Could not find file \"{0}\"", filename));
            }
            _filename = filename;

            _header = new dBaseHeader();
            // read the header
            System.IO.FileStream stream = new System.IO.FileStream(filename, System.IO.FileMode.Open, System.IO.FileAccess.Read);
            System.IO.BinaryReader binaryreader = new System.IO.BinaryReader(stream);
            _header.ReadHeader(binaryreader);

            int iCurrentRecord = 0;
            long CurrentOffset = _header.HeaderLength;
            byte DeleteChar = Convert.ToByte('*');
            int RowLength = _header.RecordLength;
            while (iCurrentRecord < _header.NumRecords)
            {
                int Val = stream.ReadByte();
                if (stream.ReadByte() != DeleteChar)
                {
                    _offsets.Add(CurrentOffset);
                    OffsetsCopy.Add(CurrentOffset);
                    iCurrentRecord++;
                }
                stream.Seek(RowLength - 1, System.IO.SeekOrigin.Current);
                CurrentOffset += RowLength;
            }
            binaryreader.Close();
            stream.Close();
            binaryreader.Close();
            return OffsetsCopy;




        }
开发者ID:zhongshuiyuan,项目名称:mapwindowsix,代码行数:53,代码来源:dBaseIndex.cs

示例4: RunScanner

        public static void RunScanner()
        {
            string thishost = System.Net.Dns.GetHostName();
            Random rnd = new Random(unchecked(DateTime.Now.Millisecond
                + System.Diagnostics.Process.GetCurrentProcess().Id
                + 7179259));

            // Random sleep to hit surrogate\dfs.xml at different times.
            System.Threading.Thread.Sleep(rnd.Next(5000, 30000));

            MySpace.DataMining.AELight.dfs dc;
            try
            {
                dc = MySpace.DataMining.AELight.dfs.ReadDfsConfig_unlocked(
                        MySpace.DataMining.AELight.Surrogate.NetworkPathForHost(MySpace.DataMining.AELight.Surrogate.MasterHost)
                            + @"\" + MySpace.DataMining.AELight.dfs.DFSXMLNAME);
            }
            catch (System.IO.FileNotFoundException e)
            {
                if (!dfsnotfound)
                {
                    dfsnotfound = true;
                    // Just throw it once.
                    throw new System.IO.FileNotFoundException("FileDaemon scanner thread aborting"
                        + "; " + MySpace.DataMining.AELight.dfs.DFSXMLNAME + " not found", e);
                }
                dc = null;
                _ThreadDisabled();
                return;
            }

            if (null == dc.FileDaemon || !dc.FileDaemon.Enabled)
            {
                dc = null;
                _ThreadDisabled();
                return;
            }

#if optional
            try
            {
                System.IO.FileInfo fslog = new System.IO.FileInfo("filescan.log");
                if (!fslog.Exists || fslog.Length < 0x400 * 0x400)
                {
                    System.IO.File.AppendAllText("filescan.log",
                        "[" + DateTime.Now + "] " + thishost + " <enabled>"
                        + Environment.NewLine);
                }
            }
            catch
            {
            }
#endif

            for (; ; System.Threading.Thread.Sleep(1000 * 60 * 1))
            {
                string[] chunks = System.IO.Directory.GetFiles(".", "zd.*.zd");
                for (int ic = 0; ic < chunks.Length; ic++)
                {
                    int ri = rnd.Next(0, chunks.Length);
                    string s = chunks[ic];
                    chunks[ic] = chunks[ri];
                    chunks[ri] = s;
                }

#if optional
                try
                {
                    System.IO.FileInfo fslog = new System.IO.FileInfo("filescan.log");
                    if (!fslog.Exists || fslog.Length < 0x400 * 0x400)
                    {
                        System.IO.File.AppendAllText("filescan.log",
                            "[" + DateTime.Now + "] " + thishost + " <start> scanning " + chunks.Length + " chunks"
                            + Environment.NewLine);
                    }
                }
                catch
                {
                }
#endif

                for (int ic = 0; ic < chunks.Length; ic++)
                {
                    _ScanChunkSleep(dc.FileDaemon.ScanChunkSleep);

                    string chunk = chunks[ic];
                    int pos = -1;
                    try
                    {
                        using (System.IO.FileStream fs = new System.IO.FileStream(chunk,
                            System.IO.FileMode.Open, System.IO.FileAccess.Read,
                            System.IO.FileShare.ReadWrite | System.IO.FileShare.Delete))
                        {
                            pos++;
                            for (; ; )
                            {
                                int ib = fs.ReadByte();
                                if (-1 == ib)
                                {
                                    break;
//.........这里部分代码省略.........
开发者ID:erisonliang,项目名称:qizmt,代码行数:101,代码来源:FileDaemon.cs

示例5: ViewLog

        private static void ViewLog(string[] args)
        {
            int maxentries = 1000;
            string[] hosts = Utils.GetQizmtHosts();

            if (hosts.Length == 0)
            {
                Console.Error.WriteLine("No Qizmt host is found.");
                return;
            }

            List<string> logpaths = new List<string>();
            {
                string execpath = CurrentDir.Replace(':', '$');
                foreach (string host in hosts)
                {
                    logpaths.Add(@"\\" + host + @"\" + execpath + @"\errors.txt");
                }
            }           

            const int MAXBYTE = 1024 * 1024 * 64;
            int maxbytepart = MAXBYTE / logpaths.Count;
            int maxentriespart = maxentries / logpaths.Count;
            if (maxentries % logpaths.Count != 0)
            {
                maxentriespart++;
            }

            List<string[]> allentries = new List<string[]>(logpaths.Count);
            RDBMS_Admin.ThreadTools<string>.Parallel(
                new Action<string>(
                delegate(string logpath)
                {
                    if (!System.IO.File.Exists(logpath))
                    {
                        return;
                    }

                    string token = Environment.NewLine + Environment.NewLine + "[";

                    System.IO.FileStream fs = null;
                    try
                    {
                        fs = new System.IO.FileStream(logpath, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.ReadWrite);
                        if (fs.Length > maxbytepart * 2)
                        {
                            fs.Position = fs.Length - maxbytepart;
                        }

                        int ib = 0;
                        List<long> idx = new List<long>();
                        long entryStart = 0;
                        while ((ib = fs.ReadByte()) > -1)
                        {
                            if (ib == (int)token[0])
                            {
                                bool istoken = true;
                                for (int i = 1; i < token.Length; i++)
                                {
                                    if (fs.ReadByte() != (int)token[i])
                                    {
                                        istoken = false;
                                        break;
                                    }
                                }

                                if (istoken)
                                {
                                    idx.Add(entryStart);
                                    entryStart = fs.Position - 1;
                                }
                            }
                        }

                        //get the last entryStart.
                        if (idx.Count > 0)
                        {
                            if (entryStart != idx[idx.Count - 1])
                            {
                                idx.Add(entryStart);
                            }
                        }
                        else
                        {
                            //1 entry only.
                            if (fs.Length > 0)
                            {
                                idx.Add(entryStart);
                            }
                        }

                        if (idx.Count == 0)
                        {
                            return;
                        }

                        long flen = fs.Length;
                        int startidx = idx.Count > maxentriespart ? idx.Count - maxentriespart : 0;
                        long offset = idx[startidx];
                        long buflen = flen - offset;
//.........这里部分代码省略.........
开发者ID:erisonliang,项目名称:qizmt,代码行数:101,代码来源:ViewLog.cs

示例6: LoadZone

        /// <summary>
        /// Reads from ScenDat -> go to a zone and load the floors and walls onto cOuter 
        /// </summary>
        /// <param name="num"></param>
        public void LoadZone(int num)
        {
            System.IO.FileStream fsScenData = new System.IO.FileStream(@"a:\agf5ScenData.dat",System.IO.FileMode.Open);
            fsScenData.Seek(2592,System.IO.SeekOrigin.Begin); // Pacification Fields
            int iFloorByte;
            int iCell=0;
            double dStartX=2500, dStartY=0; // where the West edge starts drawing on the canvas

            double i = dStartX;
            double j = dStartY;
            while(iCell<4096)
            {
                iFloorByte = (short)fsScenData.ReadByte();

                //usByte2 = System.Net.IPAddress.NetworkToHostOrder(usByte2);
                //get which floor this int represents
                //create image with source defined floor and place on screen
                Image imgCell = new Image();
                //if(usByte2<50)
                CroppedBitmap cbReturnedBitmap = GetFloor(iFloorByte);
                if (cbReturnedBitmap == null)
                {
                    imgCell.Visibility = Visibility.Collapsed;
                    i -= 41;
                    j += 28;
                    iCell++;
                    continue;
                }
                imgCell.Tag = (string)iCell.ToString() +" ; "+ i +" ; "+ j;
                imgCell.MouseDown+=iCell2_MouseDown;
                imgCell.Source = cbReturnedBitmap;
                imgCell.Width = 82;
                imgCell.Height = 56;
                MakeTransparent(ref imgCell);
                imgCell.SetValue(Canvas.LeftProperty, i);
                imgCell.SetValue(Canvas.TopProperty,  j);
                cOuter.Children.Add(imgCell);
                i -= 41;
                j += 28;
               iCell++;

                if(iCell%64==0) // if is the beginning of a new column
                {
                    int iWhichCol = iCell / 64;
                    i = dStartX + 41 * iWhichCol;
                    j = dStartY + 28 * iWhichCol;
                }
            }
            //usByte2 = brScenData.ReadUInt16();
            //usByte2 = brScenData.ReadUInt16();
            //MessageBox.Show(usByte2.ToString());
            //brScenData.Dispose();
            fsScenData.Dispose();
        }
开发者ID:AniruddhaVarma,项目名称:BladesOfGeneforge,代码行数:58,代码来源:MainWindow.xaml.cs

示例7: ReadThreadProc

 public void ReadThreadProc()
 {               
     System.IO.FileStream fs = null;
     Evt.WaitOne();
     try
     {
         fs = new System.IO.FileStream(FilePath, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.Read);
         int ib = 0;
         while ((ib = fs.ReadByte()) > -1)
         {
         }
         Console.WriteLine(ID);
     }
     catch (Exception e)
     {
         ErrMsg.Add(e.Message);
     }
     finally
     {
         if (fs != null)
         {
             fs.Close();
             fs = null;
         }
     }
 }
开发者ID:erisonliang,项目名称:qizmt,代码行数:26,代码来源:IOCook.cs

示例8: HeartbeatThreadProc

        void HeartbeatThreadProc()
        {
            int triesremain = heartbeatretries;
            while (!badlocalhost && !stop)
            {
                try
                {
                    using (System.IO.FileStream fs = new System.IO.FileStream(heartbeattempfile, System.IO.FileMode.Create, System.IO.FileAccess.ReadWrite, System.IO.FileShare.None))
                    {
                        fs.WriteByte((byte)'T');
                        fs.Seek(0, System.IO.SeekOrigin.Begin);
                        if ((int)'T' != fs.ReadByte())
                        {
                            throw new System.IO.IOException("Heartbeat thread data written was not read back correctly.");
                        }
                        fs.Close();
                    }
                    System.IO.File.Delete(heartbeattempfile);
                    triesremain = heartbeatretries; //reset                    

                    lock (clientstm)
                    {
                        clientstm.WriteByte((byte)'h');
                    }
#if FAILOVER_DEBUG
                    System.IO.File.AppendAllText(@"c:\temp\vitalsreporter_A5B1E053-9A32-417b-8068-91A7CD5CDEAB.txt", DateTime.Now.ToString() + " heartbeat sent" + Environment.NewLine);
#endif

                    System.Threading.Thread.Sleep(heartbeattimeout);
                }
                catch(Exception e)
                {
#if FAILOVER_DEBUG
                    System.IO.File.AppendAllText(@"c:\temp\vitalsreporter_A5B1E053-9A32-417b-8068-91A7CD5CDEAB.txt", DateTime.Now.ToString() + 
                        " heartbeat thread error: " + e.ToString() + Environment.NewLine);
#endif
                    if (--triesremain <= 0)
                    {
#if FAILOVER_DEBUG
                        System.IO.File.AppendAllText(@"c:\temp\vitalsreporter_A5B1E053-9A32-417b-8068-91A7CD5CDEAB.txt", DateTime.Now.ToString() +
                            " heartbeat thread error; tries=" + triesremain.ToString() 
                            + " ;caused to break out: " + e.ToString() + Environment.NewLine);
#endif
                        break;
                    }
                }
            }
        }
开发者ID:erisonliang,项目名称:qizmt,代码行数:48,代码来源:VitalsReporter.cs

示例9: CreateFromDirectory

        public void CreateFromDirectory( string Dir, string Outfile, string[] FileOrder )
        {
            List<string> Filepaths = new List<string>();
            foreach ( string f in FileOrder ) {
                Filepaths.Add( System.IO.Path.Combine( Dir, f ) );
            }
            var Filestream = new System.IO.FileStream( Outfile, System.IO.FileMode.Create );

            uint RequiredBytesForHeader;
            uint Filecount = (uint)Filepaths.Count;
            uint TotalFilesize;
            Xorbyte = 0x55;
            //Xorbyte = 0x00;

            // 0x20 Header + 0x28 per file
            RequiredBytesForHeader = Util.Align( Filecount * 0x28u + 0x20u, 0x20u );

            TotalFilesize = RequiredBytesForHeader;
            foreach ( string Path in Filepaths ) {
                TotalFilesize += (uint)( new System.IO.FileInfo( Path ).Length );
                TotalFilesize = TotalFilesize.Align( 0x20u );
            }

            // header
            Filestream.WriteByte( (byte)'R' ); Filestream.WriteByte( (byte)'T' );
            Filestream.WriteByte( (byte)'D' ); Filestream.WriteByte( (byte)'P' );
            Filestream.Write( BitConverter.GetBytes( RequiredBytesForHeader ), 0, 4 );
            Filestream.Write( BitConverter.GetBytes( Filecount ), 0, 4 );
            Filestream.Write( BitConverter.GetBytes( TotalFilesize ), 0, 4 );
            Filestream.WriteByte( Xorbyte );
            Filestream.WriteByte( 0x28 ); Filestream.WriteByte( 0x25 );
            while ( Filestream.Length < 0x20 ) { Filestream.WriteByte( 0x00 ); }

            // header file info
            uint ptr = 0;
            foreach ( string Path in Filepaths ) {
                var fi = new System.IO.FileInfo( Path );
                uint size = (uint)( fi.Length );

                byte[] name = Encoding.ASCII.GetBytes( fi.Name );
                Filestream.Write( name, 0, Math.Min( 0x20, name.Length ) );
                for ( int i = name.Length; i < 0x20; ++i ) { Filestream.WriteByte( 0x00 ); }

                Filestream.Write( BitConverter.GetBytes( size ), 0, 4 );
                Filestream.Write( BitConverter.GetBytes( ptr ), 0, 4 );

                ptr = Util.Align( ptr + size, 0x20u );
            }
            while ( Filestream.Length < RequiredBytesForHeader ) { Filestream.WriteByte( 0x00 ); }

            // files
            foreach ( string Path in Filepaths ) {
                var File = new System.IO.FileStream( Path, System.IO.FileMode.Open );

                while ( true ) {
                    int b = File.ReadByte();
                    if ( b == -1 ) { break; }
                    Filestream.WriteByte( (byte)( b ^ Xorbyte ) );
                }

                File.Close();
                while ( Filestream.Length % 0x20 != 0 ) { Filestream.WriteByte( 0x00 ); }
            }

            Filestream.Close();
        }
开发者ID:AdmiralCurtiss,项目名称:HyoutaTools,代码行数:66,代码来源:RTDP.cs

示例10: AELightRun


//.........这里部分代码省略.........
                                                        xproc.Close();
                                                    }
                                                    catch (Exception exf)
                                                    {
                                                        if (qverbose)
                                                        {
                                                            lock (slaves)
                                                            {
                                                                Console.Write("(Unable to suspend AELight threads: {0})", exf.Message);
                                                                ConsoleFlush();
                                                            }
                                                        }
                                                    }
                                                }
                                            }

                                            System.Threading.Thread.Sleep(1000); // Allow slaves to initialize.
                                            {
                                                //foreach (string slave in slaves)
                                                MySpace.DataMining.Threading.ThreadTools<string>.Parallel(
                                                    new Action<string>(
                                                    delegate(string slave)
                                                    {
                                                        string netpath = Surrogate.NetworkPathForHost(slave);
                                                        foreach (System.IO.FileInfo fi in (new System.IO.DirectoryInfo(netpath))
                                                            .GetFiles("*.j" + killsjid + ".slave.pid"))
                                                        {
                                                            string spidStopRemote = fi.Name.Substring(0, fi.Name.IndexOf('.'));
                                                            try
                                                            {
                                                                System.Net.Sockets.NetworkStream nstm = Surrogate.ConnectService(slave);
                                                                nstm.WriteByte((byte)'k');
                                                                XContent.SendXContent(nstm, spidStopRemote);
                                                                if ('+' != nstm.ReadByte())
                                                                {
                                                                    throw new Exception("Remote machine did not report a success during kill operation");
                                                                }
                                                                nstm.Close();
                                                                fi.Delete();
                                                            }
                                                            catch (Exception e)
                                                            {
                                                                LogOutputToFile("Unable to kill Slave PID " + netpath + "\\" + spidStopRemote + " belonging to JID " + killsjid + ": " + e.ToString());
                                                            }
                                                        }
                                                    }), slaves, numthreads);
                                            }
                                            System.Threading.Thread.Sleep(1000); // Allow slaves to finalize.

                                            string killjzm = "zmap_*_*.j" + killsjid + ".zm";
                                            string killjzb = "zblock_*.j" + killsjid + ".zb";
                                            string killjoblog = "*_????????-????-????-????-????????????.j" + killsjid + "_log.txt";
                                            string killzf = "zfoil_*.j" + killsjid + ".zf";
                                            string killslaveconfig = "slaveconfig.j" + killsjid + ".xml";
                                            //foreach (string slave in slaves)
                                            MySpace.DataMining.Threading.ThreadTools<string>.Parallel(
                                                new Action<string>(
                                                delegate(string slave)
                                                {
                                                    string netpath = Surrogate.NetworkPathForHost(slave);
                                                    {
                                                        // Delete leaked chunks only! Have to check with DFS.xml
                                                        Dictionary<string, bool> dcnodes = new Dictionary<string, bool>(StringComparer.OrdinalIgnoreCase);
                                                        foreach (dfs.DfsFile df in dc.Files)
                                                        {
                                                            for (int ifn = 0; ifn < df.Nodes.Count; ifn++)
开发者ID:erisonliang,项目名称:qizmt,代码行数:67,代码来源:AELight.cs


注:本文中的System.IO.FileStream.ReadByte方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。