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


C# IO.FileStream类代码示例

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


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

示例1: RadarColorData

        static RadarColorData()
        {
            using (FileStream index = new FileStream(FileManager.GetFilePath("Radarcol.mul"), FileMode.Open, FileAccess.Read, FileShare.Read))
            {
                BinaryReader bin = new BinaryReader(index);

                // Prior to 7.0.7.1, all clients have 0x10000 colors. Newer clients have fewer colors.
                int colorCount = (int)index.Length / 2;

                for (int i = 0; i < colorCount; i++)
                {
                    uint c = bin.ReadUInt16();
                    Colors[i] = 0xFF000000 | (
                            ((((c >> 10) & 0x1F) * multiplier)) |
                            ((((c >> 5) & 0x1F) * multiplier) << 8) |
                            (((c & 0x1F) * multiplier) << 16)
                            );
                }
                // fill the remainder of the color table with non-transparent magenta.
                for (int i = colorCount; i < Colors.Length; i++)
                {
                    Colors[i] = 0xFFFF00FF;
                }

                Metrics.ReportDataRead((int)bin.BaseStream.Position);
            }
        }
开发者ID:msx752,项目名称:UltimaXNA,代码行数:27,代码来源:RadarColorData.cs

示例2: run

        public void run(string text)
        {
          iSpeechSynthesis iSpeech=  new iSpeechSynthesis(_api, _production);

           iSpeech.setVoice("usenglishfemale");
           iSpeech.setOptionalCommands("format", "mp3");
            
           TTSResult result = iSpeech.speak(text);         
            
           byte [] audioData = new byte[result.getAudioFileLength()];

           int read = 0;
           int totalRead = 0;

           while (totalRead < audioData.Length)
           {
               read = result.getStream().Read(audioData, totalRead, audioData.Length - totalRead);
               totalRead += read;
           }


           FileStream fs = new FileStream("audio.mp3", FileMode.Create);
           BinaryWriter bw = new BinaryWriter(fs);

           bw.Write(audioData, 0, audioData.Length);           

        }
开发者ID:iSpeech,项目名称:iSpeech-.Net-SDK,代码行数:27,代码来源:iSpeechTTS.cs

示例3: Load

 public void Load(BinaryReader br, FileStream fs)
 {
     Offset = br.ReadInt32();
     Offset += 16;
     FrameCount = br.ReadInt32();
     MipWidth = br.ReadInt32();
     MipHeight = br.ReadInt32();
     StartX = br.ReadInt32();
     StartY = br.ReadInt32();
     TileCount = br.ReadUInt16();
     TotalCount = br.ReadUInt16();
     CellWidth = br.ReadUInt16();
     CellHeight = br.ReadUInt16();
     Frames = new EanFrame[TotalCount];
     long curPos = fs.Position;
     fs.Seek((long)Offset, SeekOrigin.Begin);
     for (int i = 0; i < TotalCount; i++)
     {
         Frames[i].X = br.ReadUInt16();
         Frames[i].Y = br.ReadUInt16();
         Frames[i].Width = br.ReadUInt16();
         Frames[i].Height = br.ReadUInt16();
     }
     fs.Seek((long)curPos, SeekOrigin.Begin);
 }
开发者ID:linxiubao,项目名称:UniShader,代码行数:25,代码来源:UVAnimation.cs

示例4: Main

 static void Main(string[] args)
 {
     VTDGen vg = new VTDGen();
     AutoPilot ap = new AutoPilot();
     Encoding eg = System.Text.Encoding.GetEncoding("utf-8");
     //ap.selectXPath("/*/*/*");
     AutoPilot ap2 = new AutoPilot();
     ap2.selectXPath("//@*");
     if (vg.parseFile("soap2.xml", true))
     {
         FileStream fs = new FileStream("output.xml", System.IO.FileMode.OpenOrCreate);
         VTDNav vn = vg.getNav();
         ap.bind(vn);
         ap2.bind(vn);
         //ap.evalXPath();
         int i;
         while ((i = ap2.evalXPath()) != -1)
         {
             //System.out.println("attr name ---> "+ i+ " "+vn.toString(i)+"  value ---> "+vn.toString(i+1));
             vn.overWrite(i + 1, eg.GetBytes(""));
         }
         byte[] ba = vn.getXML().getBytes();
         fs.Write(ba,0,ba.Length);
         fs.Close();
     }
 }
开发者ID:IgorBabalich,项目名称:vtd-xml,代码行数:26,代码来源:erase.cs

示例5: filestream2

 //This method improves upon the naive method (stringBuffer) as ENCODING.GetString
 //allocates a new character array with every invocation, and this method bypasses
 //this by reusing the same char array.  Surprisingly in tests, this method held
 //no improvement.
 static void filestream2(string filePath, Action<string> callback)
 {
     byte[] buffer = new byte[BUFFER_SIZE];
     byte[] charBuffer = new byte[MAX_TOKEN_SIZE];
     char[] encoderBuffer = new char[ENCODING.GetMaxCharCount(MAX_TOKEN_SIZE)];
     int charIndex = 0;
     int bufferSize, encodedChars;
     using (FileStream stream = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
     {
         do
         {
             bufferSize = stream.Read(buffer, 0, BUFFER_SIZE);
             for (int i = 0; i < bufferSize; i++)
             {
                 if (scannerNoMatch(buffer[i]))
                 {
                     charBuffer[charIndex++] = buffer[i];
                 }
                 else
                 {
                     encodedChars = ENCODING.GetChars(charBuffer, 0, charIndex, encoderBuffer, 0);
                     callback(new string(encoderBuffer, 0, encodedChars));
                     charIndex = 0;
                 }
             }
         } while (bufferSize != 0);
     }
 }
开发者ID:nickbabcock,项目名称:HighPerformanceUnsafeCSharp,代码行数:32,代码来源:Program.cs

示例6: ReadBinaryFile

 public static byte[] ReadBinaryFile(string FileName)
 {
     FileStream BinaryStream = new FileStream(FileName, FileMode.Open);
     byte[] retBytes = null;
     BinaryStream.Read(retBytes, 0, BinaryStream.Length);
     return retBytes;
 }
开发者ID:okyereadugyamfi,项目名称:softlogik,代码行数:7,代码来源:DownloadService.cs

示例7: GnuPlot

        // use static factory methods!
        private GnuPlot(Table table)
        {
            try {
                // TODO avoid necessary write access in app directory
                using (FileStream fs = new FileStream (BinaryFile, FileMode.Create, FileAccess.Write))
                    using (BinaryWriter bw = new BinaryWriter (fs)) {
                        Table3D t3D = table as Table3D;
                        if (t3D != null)
                            WriteGnuPlotBinary (bw, t3D);
                        else
                            WriteGnuPlotBinary (bw, (Table2D)table);
                    }
            } catch (Exception ex) {
                throw new GnuPlotException ("Could not write binary data file.\n" + ex.Message);
            }
            try {
                StartProcess (table);
            } catch (System.ComponentModel.Win32Exception ex) {
                // from MSDN
                // These are the Win32 error code for file not found or access denied.
                const int ERROR_FILE_NOT_FOUND = 2;
                const int ERROR_ACCESS_DENIED = 5;

                switch (ex.NativeErrorCode) {
                case ERROR_FILE_NOT_FOUND:
                    throw new GnuPlotProcessException ("Could not find gnuplot executable path:\n" + exePath + "\n\n" + ex.Message);
                case ERROR_ACCESS_DENIED:
                    throw new GnuPlotProcessException ("Access denied, no permission to start gnuplot process!\n" + ex.Message);
                default:
                    throw new GnuPlotProcessException ("Unknown error. Could not start gnuplot process.\n" + ex.Message);
                }
            }
        }
开发者ID:dschultzca,项目名称:ScoobyRom,代码行数:34,代码来源:GnuPlot.cs

示例8: FileReverseReader

 public FileReverseReader(string path)
 {
     disposed = false;
     file = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
     encoding = FindEncoding(file);
     SetupCharacterStartDetector();
 }
开发者ID:andy250,项目名称:caselog,代码行数:7,代码来源:FileReverseReader.cs

示例9: ConnectExistingStream

 public void ConnectExistingStream(string path, bool readOnly = true) {
     Stream.Dispose();
     Stream = null;
     Debug.GC(true);
     Stream = new FileStream(path, FileMode.Open);
     IsReadOnly = readOnly;
 }
开发者ID:einart74,项目名称:NetduinoHelpers,代码行数:7,代码来源:VirtualMemory.cs

示例10: GetExistAccessToken

 /// 获取token,如果存在且没过期,则直接取token
 /// <summary>
 /// 获取token,如果存在且没过期,则直接取token
 /// </summary>
 /// <returns></returns>
 public static string GetExistAccessToken()
 {
     // 读取XML文件中的数据
     string filepath = System.Web.HttpContext.Current.Server.MapPath("/XMLToken.xml");
     FileStream fs = new FileStream(filepath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
     StreamReader str = new StreamReader(fs, System.Text.Encoding.UTF8);
     XmlDocument xml = new XmlDocument();
     xml.Load(str);
     str.Close();
     str.Dispose();
     fs.Close();
     fs.Dispose();
     string Token = xml.SelectSingleNode("xml").SelectSingleNode("AccessToken").InnerText;
     DateTime AccessTokenExpires = Convert.ToDateTime(xml.SelectSingleNode("xml").SelectSingleNode("AccessExpires").InnerText);
     //如果token过期,则重新获取token
     if (DateTime.Now >= AccessTokenExpires)
     {
         AccessToken mode = Getaccess();
         //将token存到xml文件中,全局缓存
         xml.SelectSingleNode("xml").SelectSingleNode("AccessToken").InnerText = mode.access_token;
         DateTime _AccessTokenExpires = DateTime.Now.AddSeconds(mode.expires_in);
         xml.SelectSingleNode("xml").SelectSingleNode("AccessExpires").InnerText = _AccessTokenExpires.ToString();
         xml.Save(filepath);
         Token = mode.access_token;
     }
     return Token;
 }
开发者ID:shinygang,项目名称:Wechat-JSSDK,代码行数:32,代码来源:JSSDK.cs

示例11: Load

 /// <summary>
 /// Loads materials from the specified stream.
 /// </summary>
 /// <param name="path">The path.</param>
 /// <param name="loadTextureImages">if set to <c>true</c> texture images
 /// will be loaded and set in the <see cref="TextureMap.Image"/> property.</param>
 /// <returns>The results of the file load.</returns>
 public static FileLoadResult<List<Material>> Load(string path, bool loadTextureImages)
 {
     //  Create a streamreader and read the data.
     using(var stream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read))
     using (var streamReader = new StreamReader(stream))
         return Read(streamReader, path, loadTextureImages);
 }
开发者ID:stiter,项目名称:file-format-wavefront,代码行数:14,代码来源:FileFormatMtl.cs

示例12: Main

        public static void Main()
        {

#if NETDUINO_MINI
            StorageDevice.MountSD("SD", SPI.SPI_module.SPI1, Pins.GPIO_PIN_13);
#else
            StorageDevice.MountSD("SD", SPI.SPI_module.SPI1, Pins.GPIO_PIN_D10);
#endif

            using (var filestream = new FileStream(@"SD\resources.txt", FileMode.Open))
            {
                StreamReader reader = new StreamReader(filestream);
                Debug.Print(reader.ReadToEnd());
                reader.Close();
            }

            using (var filestream = new FileStream(@"SD\dontpanic.txt", FileMode.Create))
            {
                StreamWriter streamWriter = new StreamWriter(filestream);
                streamWriter.WriteLine("This is a test of the SD card support on the netduino...This is only a test...");
                streamWriter.Close();
            }

            StorageDevice.Unmount("SD");
        }
开发者ID:aaronfisher,项目名称:x10ToSmartthings,代码行数:25,代码来源:Program.cs

示例13: AppendTest

 public void AppendTest()
 {
     /*
      * TODO : Add proper values for
      * infile  : signed file without payload
      * outFile : file to be written
      * outFile : reference file. A working file wher payload already appended
      */
     var inFile = "";
     var outFile = "";
     var reference = "";
     var payload = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?></xml>";
     if (File.Exists(inFile))
     {
         using (var inputFile = File.OpenRead(inFile))
         {
             using (var outputFile = new FileStream(outFile, FileMode.OpenOrCreate))
             {
                 Payload.Append(inputFile, outputFile, payload);
             }
         }
         var actual = File.ReadAllBytes(outFile);
         var expected = File.ReadAllBytes(reference);
         Assert.AreEqual(expected, actual);
     }
 }
开发者ID:rtezli,项目名称:PePayload,代码行数:26,代码来源:PayloadTests.cs

示例14: Main

        static void Main(string[] args)
        {
            FileStream filStream;
            BinaryWriter binWriter;

            Console.Write("Enter name of the file: ");
            string fileName = Console.ReadLine();
            if (File.Exists(fileName))
            {
                Console.WriteLine("File - {0} already exists!", fileName);
            }
            else
            {
                filStream = new FileStream(fileName, FileMode.CreateNew);
                binWriter = new BinaryWriter(filStream);
                decimal aValue = 2.16M;
                binWriter.Write("Sample Run");
                for (int i = 0; i < 11; i++)
                {

                    binWriter.Write(i);
                }
                binWriter.Write(aValue);

                binWriter.Close();
                filStream.Close();
                Console.WriteLine("File Created successfully");
            }

            Console.ReadKey();
        }
开发者ID:moeen-aqrabawi,项目名称:C-.NET,代码行数:31,代码来源:BinaryExample.cs

示例15: Reader

 public static String Reader()
 {
     try
     {
         FileStream fs = new FileStream(getURL(), FileMode.OpenOrCreate, FileAccess.Read, FileShare.Read);
         StreamReader r = new StreamReader(fs);
         hostsFile = r.ReadToEnd();
         r.Close();
         fs.Close();
         return hostsFile;
     }
     catch (UnauthorizedAccessException)
     {
         return "Access denied";
     }
     catch (IOException)
     {
         return "Host not found.";
     }
     catch (ArgumentException)
     {
         return "Please, enter IP Address or Host name.";
     }
     catch (Exception) { return null; }
 }
开发者ID:vilabesto,项目名称:HostsEditor,代码行数:25,代码来源:hostsChanger.cs


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