• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# IO.FileStream类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: DeCrypting

 private static string DeCrypting()
 {
     var res = string.Empty;
     var file = new FileStream(Controller.GetPath(), FileMode.Open, FileAccess.Read, FileShare.None, 32, FileOptions.SequentialScan);
     var reader = new BinaryReader(file);
     var writer = new BinaryWriter(new FileStream(Processor.GetNewName(Controller.GetPath()), FileMode.Create, FileAccess.Write,
         FileShare.None, 32, FileOptions.WriteThrough));
     try
     {
         var pos = 0;
         while (pos < file.Length)
         {
             var c = reader.ReadUInt16();
             //var pow = Processor.fast_exp(c, Controller.GetKc(), Controller.GetR());
             var pow = Processor.Pows(c, Controller.GetKc(), Controller.GetR());
             if (pos < 256) res += pow + " ";
             writer.Write((byte)(pow));
             pos += 2;
         }
     }
     finally
     {
         writer.Close();
         reader.Close();
     }
     return "Decoding Complete!\n" + res;
 }
开发者ID:Emaxan,项目名称:TI_Laba4_RSA,代码行数:27,代码来源:Decoding.cs


示例17: Main

        static void Main(string[] args)
        {
            //AsyncReadOneFile();

            //AsyncReadMultiplyFiles();

            FileStream fs = new FileStream(@"../../Program.cs", FileMode.Open,
               FileAccess.Read, FileShare.Read, 1024,
               FileOptions.Asynchronous);

            Byte[] data = new Byte[100];

            IAsyncResult ar = fs.BeginRead(data, 0, data.Length, null, null);

            while (!ar.IsCompleted)
            {
                Console.WriteLine("Операция не завершена, ожидайте...");
                Thread.Sleep(10);
            }

            Int32 bytesRead = fs.EndRead(ar);

            fs.Close();

            Console.WriteLine("Количество считаных байт = {0}", bytesRead);
            Console.WriteLine(Encoding.UTF8.GetString(data).Remove(0, 1));
        }
开发者ID:xs2ranjeet,项目名称:13ns9-1spr,代码行数:27,代码来源:Program.cs


示例18: WriteToLog

 /// <summary>
 /// Запись в ЛОГ-файл
 /// </summary>
 /// <param name="str"></param>
 public void WriteToLog(string str, bool doWrite = true)
 {
     if (doWrite)
     {
         StreamWriter sw = null;
         FileStream fs = null;
         try
         {
             string curDir = AppDomain.CurrentDomain.BaseDirectory;
             fs = new FileStream(curDir + "teplouchetlog.pi", FileMode.Append, FileAccess.Write, FileShare.ReadWrite);
             sw = new StreamWriter(fs, Encoding.Default);
             if (m_vport == null) sw.WriteLine(DateTime.Now.ToString() + ": Unknown port: adress: " + m_address + ": " + str);
             else sw.WriteLine(DateTime.Now.ToString() + ": " + m_vport.GetName() + ": adress: " + m_address + ": " + str);
             sw.Close();
             fs.Close();
         }
         catch
         {
         }
         finally
         {
             if (sw != null)
             {
                 sw.Close();
                 sw = null;
             }
             if (fs != null)
             {
                 fs.Close();
                 fs = null;
             }
         }
     }
 }
开发者ID:Prizmer,项目名称:tu_teplouchet,代码行数:38,代码来源:CMeter.cs


示例19: addConfigFile

        void addConfigFile(string configFilename)
        {
            var dirName = Utils.getDirName(Utils.getFullPath(configFilename));
            addAssemblySearchPath(dirName);

            try {
                using (var xmlStream = new FileStream(configFilename, FileMode.Open, FileAccess.Read, FileShare.Read)) {
                    var doc = new XmlDocument();
                    doc.Load(XmlReader.Create(xmlStream));
                    foreach (var tmp in doc.GetElementsByTagName("probing")) {
                        var probingElem = tmp as XmlElement;
                        if (probingElem == null)
                            continue;
                        var privatePath = probingElem.GetAttribute("privatePath");
                        if (string.IsNullOrEmpty(privatePath))
                            continue;
                        foreach (var path in privatePath.Split(';'))
                            addAssemblySearchPath(Path.Combine(dirName, path));
                    }
                }
            }
            catch (IOException) {
            }
            catch (XmlException) {
            }
        }
开发者ID:GodLesZ,项目名称:ConfuserDeobfuscator,代码行数:26,代码来源:AssemblyResolver.cs


示例20: Tkhd

        public Tkhd(FileStream fs)
        {
            Buffer = new byte[84];
            int bytesRead = fs.Read(Buffer, 0, Buffer.Length);
            if (bytesRead < Buffer.Length)
                return;

            int version = Buffer[0];
            int addToIndex64Bit = 0;
            if (version == 1)
                addToIndex64Bit = 8;

            TrackId = GetUInt(12 + addToIndex64Bit);
            if (version == 1)
            {
                Duration = GetUInt64(20 + addToIndex64Bit);
                addToIndex64Bit += 4;
            }
            else
            {
                Duration = GetUInt(20 + addToIndex64Bit);
            }

            Width = (uint)GetWord(76 + addToIndex64Bit); // skip decimals
            Height = (uint)GetWord(80 + addToIndex64Bit); // skip decimals
            //System.Windows.Forms.MessageBox.Show("Width: " + GetWord(76 + addToIndex64Bit).ToString() + "." + GetWord(78 + addToIndex64Bit).ToString());
            //System.Windows.Forms.MessageBox.Show("Height: " + GetWord(80 + addToIndex64Bit).ToString() + "." + GetWord(82 + addToIndex64Bit).ToString());
        }
开发者ID:athikan,项目名称:subtitleedit,代码行数:28,代码来源:Tkhd.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# IO.FileSystem类代码示例发布时间:2022-05-26
下一篇:
C# IO.FileSecurityState类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap