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


C# FileStream.ReadByte方法代码示例

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


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

示例1: DecryptFile

        public static void DecryptFile(string strKey, string pathCypheredTextFile, string pathPlainTextFile)
        {
            // Place la clé de déchiffrement dans un tableau d'octets
            byte[] key = GenerateAlgotihmInputs(strKey);

            // Place le vecteur d'initialisation dans un tableau d'octets
            byte[] iv = GenerateAlgotihmInputs(strKey);

            // Filestream of the new file that will be decrypted.
            Directory.CreateDirectory(Directory.GetParent(pathPlainTextFile).FullName);
            FileStream fsCrypt = new FileStream(pathPlainTextFile, FileMode.Create);

            RijndaelManaged rijndael = new RijndaelManaged();
            rijndael.Mode = CipherMode.CBC;
            rijndael.Key = key;
            rijndael.IV = iv;

            ICryptoTransform aesDecryptor = rijndael.CreateDecryptor();

            CryptoStream cs = new CryptoStream(fsCrypt, aesDecryptor, CryptoStreamMode.Write);

            // FileStream of the file that is currently encrypted.
            FileStream fsIn = new FileStream(pathCypheredTextFile, FileMode.OpenOrCreate);

            int data;

            while ((data = fsIn.ReadByte()) != -1)
                cs.WriteByte((byte)data);
            cs.Close();
            fsIn.Close();
            fsCrypt.Close();
        }
开发者ID:BenoitCharret,项目名称:visualStudio,代码行数:32,代码来源:EncryptionHelper.cs

示例2: calculateF2Checksum

        public uint calculateF2Checksum(string a_fileName, int start, int length)
        {
            FileStream fs = new FileStream(a_fileName, FileMode.Open, FileAccess.Read);
            uint[] xorTable = new uint[8] { 0x81184224, 0x24421881, 0xc33c6666, 0x3cc3c3c3,
                                           0x11882244, 0x18241824, 0x84211248, 0x12345678 };
            byte[] data = new byte[4];
            byte xorCount;
            uint temp = 0;
            uint checksum = 0;
            uint count = 0;

            fs.Position = start;
            checksum = 0;
            count = 0;
            xorCount = 1;

            while( count < length && fs.Position < 0x7FFFF )
            {
                data[0] = (byte)fs.ReadByte();
                data[1] = (byte)fs.ReadByte();
                data[2] = (byte)fs.ReadByte();
                data[3] = (byte)fs.ReadByte();
                temp = (uint)(data[0] << 24 | data[1] << 16 | data[2] << 8 | data[3]);
                checksum += temp ^ xorTable[xorCount++];
                if( xorCount > 7 ) xorCount = 0;
                count += 4;
            }

            checksum ^= 0x40314081;
            checksum -= 0x7FEFDFD0;
            fs.Close();
            return checksum;
        }
开发者ID:ChrisPea,项目名称:TuningSuites,代码行数:33,代码来源:ChecksumHandler.cs

示例3: OpenStream

 public static StreamReader OpenStream(FileStream fs, Encoding suggestedEncoding, Encoding defaultEncoding)
 {
     if (fs.Length > 3) {
         // the autodetection of StreamReader is not capable of detecting the difference
         // between ISO-8859-1 and UTF-8 without BOM.
         int firstByte = fs.ReadByte();
         int secondByte = fs.ReadByte();
         switch ((firstByte << 8) | secondByte) {
             case 0x0000: // either UTF-32 Big Endian or a binary file; use StreamReader
             case 0xfffe: // Unicode BOM (UTF-16 LE or UTF-32 LE)
             case 0xfeff: // UTF-16 BE BOM
             case 0xefbb: // start of UTF-8 BOM
                 // StreamReader autodetection works
                 fs.Position = 0;
                 return new StreamReader(fs);
             default:
                 return AutoDetect(fs, (byte)firstByte, (byte)secondByte, defaultEncoding);
         }
     } else {
         if (suggestedEncoding != null) {
             return new StreamReader(fs, suggestedEncoding);
         } else {
             return new StreamReader(fs);
         }
     }
 }
开发者ID:jumpinjackie,项目名称:fdotoolbox,代码行数:26,代码来源:FileReader.cs

示例4: main

        public static void main()
        {
            FileStream infile, outfile;

            int tam, dig = 0, let = 0, outr = 0;
            char x, y;

            infile = new System.IO.FileStream("teste-20140217.txt", System.IO.FileMode.Open, System.IO.FileAccess.Read);
            outfile = new System.IO.FileStream("teste2-20140217.txt", System.IO.FileMode.Create, System.IO.FileAccess.Write);

            tam = (int)infile.Length;

            for (int i = 0; i < tam; ++i) {
                x = (char)infile.ReadByte();
                if (x == ' ')
                    continue;
                else if (x == '#')
                {
                    do
                    {
                        i++;
                        y = (char)infile.ReadByte();
                    } while (y != '#');
                }
                else
                {
                    outfile.WriteByte((byte)x);
                }
            }
            outfile.Close();
        }
开发者ID:jcbombardelli,项目名称:Algoritmando,代码行数:31,代码来源:Compiladores20140217.cs

示例5: Slice

        /* INPUT 1:
        ../../Faded.mp4
        ../../
        5
        INPUT 2:
        ../../text.txt
        ../../
        3

         * * * */
        private static void Slice(string sourceFile, string destinationDirectory, int parts)
        {
            FileStream reader = new FileStream(sourceFile, FileMode.Open);
            FileInfo file = new FileInfo(sourceFile);
            long chunkSize = (long)(file.Length/parts);
            BigInteger counter = -1;
            if (file.Length%2 == 1)
            {
                counter = 0;
            }
            int fileCounter = 1;
            int readBytesVariable = reader.ReadByte();
            List<byte> lsBytes = new List<byte>();
            lsBytes.Add((byte)readBytesVariable);
            while (readBytesVariable != -1)
            {

                if ((counter%chunkSize == 0 && counter != 0) || counter == file.Length)
                {
                    string fileName = destinationDirectory + "Part-" + fileCounter + "." + sourceFile.Split(new char[]{'.'},StringSplitOptions.RemoveEmptyEntries).LastOrDefault();
                    FileStream writer = new FileStream(fileName, FileMode.Create,FileAccess.Write);
                    writer.Write(lsBytes.ToArray(), 0,lsBytes.Count);
                    writer.Flush();
                    writer.Dispose();
                    lsBytes.Clear();
                    fileCounter++;
                }

                readBytesVariable = reader.ReadByte();
                lsBytes.Add((byte)readBytesVariable);
                counter++;
            }
        }
开发者ID:exploitx3,项目名称:C-Sharp-,代码行数:43,代码来源:Slicing+File.cs

示例6: HideMessage

        /// <summary>
        ///  This function enabels you to hide a message insider a BMP
        /// </summary>
        /// <param name="inputPath">input BMP path</param>
        /// <param name="outputPath">output BMP path</param>
        /// <param name="message">message to hide</param>
        public void HideMessage(string inputPath,string outputPath,string message)
        {
            int readByte;
            int count=14;
            BMP bitmap=new BMP(inputPath);
            bitmap.BitmapFileHeader.bfOffBits+=(message.Length+1);
            bitmap.BitmapFileHeader.bfSize+=(message.Length+1);

            FileStream br=new FileStream(inputPath,FileMode.Open);
            BinaryWriter bw=new BinaryWriter(File.OpenWrite(outputPath));

            bitmap.WriteBMPFileHeader(bw);
            br.Seek(14,SeekOrigin.Begin);

            while(count<(bitmap.BitmapFileHeader.bfOffBits-(message.Length+1)))
            {
                bw.Write((byte)br.ReadByte());
                count++;
            }
            for(int i=0;i<message.Length;i++)
            {
                bw.Write(message[i]);
            }
            bw.Write(Convert.ToByte(message.Length));

            while((readByte=br.ReadByte())>=0)
            {
                bw.Write((byte)readByte);
            }
            bw.Close();
            br.Close();
        }
开发者ID:hexcone,项目名称:ASECPJ,代码行数:38,代码来源:Stegano.cs

示例7: PE

        public PE(string fileName)
        {
            FileName = Path.GetFullPath(fileName);
            Uri = new Uri(FileName);
            IsPEFile = false;
            try
            {
                _fs = File.OpenRead(FileName);

                byte byteRead = (byte)_fs.ReadByte();
                if (byteRead != 'M') { return; }

                byteRead = (byte)_fs.ReadByte();
                if (byteRead != 'Z') { return; }
                _fs.Seek(0, SeekOrigin.Begin);

                _peReader = new PEReader(_fs);
                PEHeaders = _peReader.PEHeaders;
                IsPEFile = true;
            }
            catch (IOException e) { LoadException = e; }
            catch (BadImageFormatException e) { LoadException = e; }
            catch (UnauthorizedAccessException e) { LoadException = e; }

            if (IsPEFile)
            {
                m_pImage = new SafePointer(_peReader.GetEntireImage().GetContent().ToBuilder().ToArray());

                if (IsManaged)
                {
                    _metadataReader = _peReader.GetMetadataReader();
                }
            }
        }
开发者ID:blinds52,项目名称:binskim,代码行数:34,代码来源:PE.cs

示例8: main

        public static void main()
        {
            FileStream infile, outfile;

            int tam, dig = 0, let = 0, outr = 0;
            char x, y;
            List<String> a = new List<String>();

            infile = new System.IO.FileStream("teste-20140224.txt", System.IO.FileMode.Open, System.IO.FileAccess.Read);

            tam = (int)infile.Length;

            for (int i = 0; i < tam; ++i)
            {
                x = (char)infile.ReadByte();

                if (char.IsNumber(x))
                {
                    String valor = "";
                    do
                    {
                        valor += x;
                        i++;
                        x = (char)infile.ReadByte();

                    } while (char.IsNumber(x));
                    Console.WriteLine(valor);
                }
            }

            Console.ReadKey();
        }
开发者ID:jcbombardelli,项目名称:Algoritmando,代码行数:32,代码来源:Compiladores20140224.cs

示例9: Init

 public static void Init(string DofusPath)
 {
     mDofusPath = DofusPath;
     foreach (string File in Directory.GetFiles(mDofusPath + "\\app\\content\\gfx\\items\\"))
     {
         if (File.Contains("bitmap"))
         {
             mystream = new FileStream(File, FileMode.Open, FileAccess.Read);
             byte num = Convert.ToByte(mystream.ReadByte() + mystream.ReadByte());
             if (num == 3)
             {
                 mystream.Position = mystream.Length - 0x18L;
                 int num2 = Convert.ToInt32(readUInt());
                 readUInt();
                 int num3 = Convert.ToInt32(readUInt());
                 int num4 = Convert.ToInt32(readUInt());
                 int num1 = Convert.ToInt32(readUInt());
                 int num10 = Convert.ToInt32(readUInt());
                 mystream.Position = num3;
                 int num5 = num4;
                 for (int i = 1; i <= num5; i++)
                 {
                     string key = readString();
                     int num7 = (int)(readUInt() + num2);
                     int num8 = (int)(readUInt());
                     DictionnaryItemGFX.Add(key, new int[] {
                         num7,
                         num8
                     });
                 }
                 mystream.Close();
             }
         }
     }
 }
开发者ID:DjTrilogic,项目名称:BlueSheep,代码行数:35,代码来源:ImageManager.cs

示例10: ExtractText

 /// <summary>
 /// 导出文本
 /// </summary>
 public void ExtractText()
 {
     string exportedFile = ExportGBNB(true);
     if (exportedFile.Equals(string.Empty))
     {
         Console.WriteLine("文件:{0}不包含文本", fileToProc.FullName);
         return;
     }
     List<string> text = new List<string>();
     using (FileStream reader = new FileStream(exportedFile, FileMode.Open, FileAccess.Read))
     {
         GBNB gbnb = GetGBNBInfo(reader);
         reader.Seek(gbnb.TextOffset, SeekOrigin.Begin);
         for (int i = 0; i < gbnb.SentenceCount; i++)
         {
             List<byte> textData = new List<byte>();
             byte singleData = (byte)reader.ReadByte();
             while (singleData != 0)
             {
                 textData.Add(singleData);
                 singleData = (byte)reader.ReadByte();
             }
             text.Add(Encoding.GetEncoding(932).GetString(textData.ToArray()));
         }
         WriteAllText(text, exportedFile + ".xml");
         //File.WriteAllLines(exportedFile + ".txt", text.ToArray(), Encoding.UTF8);
     }
 }
开发者ID:romhackingvn,项目名称:Alpha-Translation,代码行数:31,代码来源:MainProcessor.cs

示例11: Read

        /// <summary>
        /// Reads bytes from FileStream, decodes them, and then returns them
        /// </summary>
        /// <param name="r">FileStream to read from</param>
        /// <returns>Unencoded ride bytes</returns>
        public static byte[] Read(FileStream r)
        {
            List<byte> decodedBytes = new List<byte>();

            while (r.Position < r.Length - 4) // - 4 to strip checksum
            {
                int b = r.ReadByte();

                if (b >= 0 && b <= 128)
                {
                    // pos, read next b bytes
                    for (int i = 0; i <= b; i++)
                    {
                        decodedBytes.Add((byte)r.ReadByte());
                    }
                }
                else
                {
                    // neg, repeat next byte (1 - b) times
                    byte repeatByte = (byte)r.ReadByte();
                    int repeatTimes = (byte)(1 - b);

                    for (int i = 0; i < repeatTimes; i++)
                    {
                        decodedBytes.Add(repeatByte);
                    }
                }
            }

            return decodedBytes.ToArray();
        }
开发者ID:AlbinoDrought,项目名称:RCTGenSharp,代码行数:36,代码来源:IO.cs

示例12: Read

        public string Read(string valueName)
        {
            try
            {
                using (FileStream f = new FileStream(MakePath(valueName), FileMode.Open))
                {
                    if (f.ReadByte() != 0) return null;
                    var b = f.ReadByte();
                    if (b < 0) return null;
                    byte csum = (byte)b;

                    MemoryStream ms = new MemoryStream();
                    while (true)
                    {
                        b = f.ReadByte();
                        if (b < 0)
                        {
                            if (csum == 0) return Encoding.UTF8.GetString(ms.ToArray());
                            return null;
                        }

                        ms.WriteByte((byte)b);
                        csum -= (byte)b;
                    }
                }
            }

            catch(IOException)
            {
                return null;
            }
        }
开发者ID:MEDVEDx64,项目名称:MedvedChat,代码行数:32,代码来源:ValueFile.cs

示例13: Execute

        public static int Execute( List<string> args )
        {
            if ( args.Count == 0 ) {
                Console.WriteLine( "This is intended to help extracting skit audio from the Xbox 360 game files." );
                Console.WriteLine( "Do the following in order:" );
                Console.WriteLine( "-- unpack chat.svo (FPS4 archive, with HyoutaTools -> ToVfps4e)" );
                Console.WriteLine( "-- decompress individual skit with xbdecompress" );
                Console.WriteLine( "-- unpack skit (FPS4 archive, with HyoutaTools -> ToVfps4e)" );
                Console.WriteLine( "-- cut SE3 header from audio file to get a nub archive" );
                Console.WriteLine( "   (file 0004, seems to be 0x800 bytes for skits but can be bigger, first four bytes of new file should be 0x00020100)" );
                Console.WriteLine( "-- extract nub archive with NUBExt r12beta" );
                Console.WriteLine( "-- this gives you an \"xma\" file that isn't actually an xma, run this tool on it" );
                Console.WriteLine( "-- resulting file is a valid enough xma file that can be converted to WAV with \"toWav\"" );
                return -1;
            }

            string filename = args[0];
            using ( var source = new FileStream( filename, FileMode.Open ) ) {
                using ( var dest = new FileStream( filename + "-real.xma", FileMode.Create ) ) {
                    source.Position = 0x100;
                    int dataLength = (int)( source.Length - source.Position );

                    dest.WriteAscii( "RIFF" );
                    dest.WriteUInt32( (uint)dataLength + 0x34 );
                    dest.WriteAscii( "WAVE" );
                    dest.WriteAscii( "fmt " );

                    dest.WriteUInt32( 0x20 );

                    source.Position = 0xBC;
                    dest.WriteUInt16( source.ReadUInt16().SwapEndian() );
                    dest.WriteUInt16( source.ReadUInt16().SwapEndian() );
                    dest.WriteUInt16( source.ReadUInt16().SwapEndian() );
                    dest.WriteUInt16( source.ReadUInt16().SwapEndian() );
                    dest.WriteUInt16( source.ReadUInt16().SwapEndian() );
                    dest.WriteByte( (byte)source.ReadByte() );
                    dest.WriteByte( (byte)source.ReadByte() );
                    dest.WriteUInt32( source.ReadUInt32().SwapEndian() );
                    dest.WriteUInt32( source.ReadUInt32().SwapEndian() );
                    dest.WriteUInt32( source.ReadUInt32().SwapEndian() );
                    dest.WriteUInt32( source.ReadUInt32().SwapEndian() );
                    dest.WriteByte( (byte)source.ReadByte() );
                    dest.WriteByte( (byte)source.ReadByte() );
                    dest.WriteUInt16( source.ReadUInt16().SwapEndian() );

                    dest.WriteAscii( "data" );
                    dest.WriteUInt32( (uint)dataLength );

                    source.Position = 0x100;
                    Util.CopyStream( source, dest, dataLength );
                }
            }

            return 0;
        }
开发者ID:AdmiralCurtiss,项目名称:HyoutaTools,代码行数:55,代码来源:FixHeader.cs

示例14: WriteOnlyThrows

        public void WriteOnlyThrows()
        {
            using (FileStream fs = new FileStream(GetTestFilePath(), FileMode.Create, FileAccess.Write))
            {
                Assert.Throws<NotSupportedException>(() => fs.ReadByte());

                fs.Dispose();
                // Disposed checking happens first
                Assert.Throws<ObjectDisposedException>(() => fs.ReadByte());
            }
        }
开发者ID:noahfalk,项目名称:corefx,代码行数:11,代码来源:ReadByte.cs

示例15: ReadAllLines

 public static string[] ReadAllLines(string path)
 {
     List<string> plain = new List<string>();
     string plainBuf = "";
     FileStream stream = new FileStream(path, FileMode.Open, FileAccess.Read);
     if (stream.ReadByte() == 0)
     {
         //Encrypted
         RC4Encryption enc = new RC4Encryption(Config.I.FilePassword);
         int read = 0;
         while (read != -1 && stream.Position < stream.Length)
         {
             read = stream.ReadByte();
             char p = (char)(read ^ enc.NextByte());
             if (p == "\n".ToCharArray()[0])
             {
                 if (plainBuf.EndsWith("\r"))
                     plainBuf.Remove(plainBuf.LastIndexOf("\r"));
                 if (!string.IsNullOrEmpty(plainBuf))
                     plain.Add(plainBuf);
                 plainBuf = "";
             }
             else
                 plainBuf += p;
         }
     }
     else
     {
         //Plain
         stream.Seek(0, SeekOrigin.Begin);
         int read = 0;
         while (read != -1 && stream.Position < stream.Length)
         {
             read = stream.ReadByte();
             char p = (char)(read);
             if (p == "\n".ToCharArray()[0])
             {
                 if (plainBuf.EndsWith("\r"))
                     plainBuf.Remove(plainBuf.LastIndexOf("\r"));
                 if (!string.IsNullOrEmpty(plainBuf))
                     plain.Add(plainBuf);
                 plainBuf = "";
             }
             else
                 plainBuf += p;
         }
     }
     stream.Close();
     if (!string.IsNullOrEmpty(plainBuf))
         plain.Add(plainBuf);
     return plain.ToArray();
 }
开发者ID:bwall,项目名称:bwall-s-smaller-projects,代码行数:52,代码来源:FileEncryption.cs


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